Django18初体验
1098 浏览 5 years, 11 months
11.13 视图和模板上下文
版权声明: 转载请注明出处 http://www.codingsoho.com/from django.shortcuts import render
# Create your views here.
def home(request):
title = 'Welcome'
if request.user.is_authenticated():
title = "My title is %s" % (request.user)
context = {
"title": title,
}
return render(request, "home.html", context)
home.html
<h1>{{title}}</h1>
{{user}}
{{request.user}}
这两个user分别是由下面的middleware传进来的
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',