模板的基本使用
使用模板渲染数据
-
准备模板文件目录
在工程根目录下创建模板文件目录templates
-
配置模板
在settings.py配置文件中修改TEMPLATES配置项的DIRS值:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [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', ], }, },