外键添加:book = models.ForeignKey('BookInfo', on_delete=models.CASCADE,)
return: render_to_response
from django.shortcuts import render_to_response
import datetime
def current_datetime(request):
now = datetime.datetime.now()
return render_to_response('current_datetime.html', {'current_date': now})
修改模板路径:
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')] #自定义templates文件夹的绝对路径
页面中url写法:<a href={% url 'add' xx.id %}>
urls.py: add/<int:id>
views.py: add(request,id='')
加csrf:
django.middleware.csrf.CsrfResponseMiddleware
页面:{% csrf_token %}
views.py:
from django.views.decorators.csrf import csrf_exempt
@csrf_exempt
def contact(request):
model.py:自增长:models.AutoField(primary_key=True)
页面中输出日期:{{ stu.birthder|date:'Y-m-d'}}
xadmin使用:http://www.cnblogs.com/pgxpython/p/10217888.html
https://blog.csdn.net/p571912102/article/details/82180034
pip:https://www.cnblogs.com/xiexiaoxiao/p/7147920.html
静态文件settings.py:
STATICFILES_DIRS = [
os.path.join(BASE_DIR, 'static'),
]