TEMPLATES = [ #模版
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')] # 模版文件夹
....
],
},
]
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ title }}</title>
</head>
<body>
<ul>
{% for item in list%}
<li>{{ item }}</li>
{% endfor %}
</ul>
</body>
</html>
from django.http import HttpResponse, request
from django.shortcuts import render
'''
定义了一个试图函数
requset : 请求的request
'''
def hello(request):
# 传递给模板的数据
context = {'title': '我是模板', 'list': range(10)}
return render(request, 'hello/index.html', context)
#return HttpResponse("你好,我是模块!")
欢迎光临 黑马程序员技术交流社区 (http://bbs.itheima.com/) | 黑马程序员IT技术论坛 X3.2 |