mysite\templates\west文件夹下面的
templay.html文件内容:
<h1>{{ label }}</h1>
修改mysite/settings.py
‘DIRS’: [
os.path.join(BASE_DIR, ‘templates/west’)
],
修改west/views.py,增加一个新的对象,用于向模板提交数据:
def templay(request):
context = {}
context[‘label’] = ‘Hello World!’
return render(request, ‘templay.html’, context)
修改west/urls.py
url(r’^templay/’,views.templay),
访问http://127.0.0.1:8000/west/templay,可以看到页面:
修改上次的west/views.py中的staff:
将数据库中的数据放入到context中 继续阅读“Python Django框架 2019(03)”