templates
- 返回模板文件:
- 创建templates文件夹:
mkdir supporter/templates - 创建index.html文件:
vim supporter/templates/index.html - body中添加测试内容:
<h1>hello django</h1> - 修改项目设置:
TEMPLATES = [ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [ os.path.join(BASE_DIR, 'supporter/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', ], }, }, - 修改supporter/views.index方法:
return render(request=request, template_name='index.html') - 访问:http::127.0.0.1:8000/supporter/
- 创建templates文件夹:
- 数据渲染:
- 返回模板文件时添加:
return render(request=request, template_name='index.html', context={'hello': 'hello django!!!'}) - 模板引擎中渲染:
<h1>{{ hello }}</h1>
- 返回模板文件时添加: