python——template (一)

来源:互联网 发布:手机怎么变成2g网络了 编辑:程序博客网 时间:2024/06/06 07:06

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’)

0 0
原创粉丝点击