1.文件说明 settings.py:Generated by ‘django-admin startproject’ using Django 1.9.6.
2.# Build paths inside the project like this: os.path.join(BASE_DIR, …)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(file)))
3.TEMPLATES = [
{
‘BACKEND’: ‘django.template.backends.django.DjangoTemplates’,
‘DIRS’: [os.path.join(BASE_DIR, “templates”)],
‘APP_DIRS’: True,
‘OPTIONS’: {
‘context_processors’: [
‘django.template.context_processors.debug’,
‘django.template.context_processors.request’,
‘django.contrib.auth.context_processors.auth’,
‘django.contrib.messages.context_processors.messages’,
],
},
]
注: 'DIRS': [os.path.join(BASE_DIR, "templates")],join函数的用法需要理解,是将几个字符串拼接成一个路径。是变长参数列表,一级一级拼接。参数值给错会提示找不到模块。
4.views.py文件
from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.
def hello(request):
return render(request,’tomorrow.html’)
本文详细介绍了使用Django1.9.6创建项目的settings.py配置文件的各项设置,包括项目基本目录定义、模板路径配置等内容处理器的设定,并展示了views.py中视图函数的基本构造。
1203

被折叠的 条评论
为什么被折叠?



