2011-05-04 40 views
0

我在Django 1.3中有项目。为了显示用户名中的所有页面我base.html文件是否可以自动将用户包含到所有模板?

{% if user.is_authenticated %} 
    <p>Welcome, {{ user.username }}. 
    <a href="/proc/accounts/logout/">loggout</a></p> 
{% else %} 
    <a href="/proc/accounts/login/">loggin</a> 
{% endif %} 

使用这种标签但是,如果我不从视图中的用户模板为空值返回context_instance=RequestContext(request)'django.contrib.auth.context_processors.auth'包含在TEMPLATE_CONTEXT_PROCESSORS中。

是否有可能automaticaly包括用户到所有模板?

回答

1

因为django 1.3。使用shortcuts.render函数,并不要担心requestcontext包括您的意见

1

你自己给出了答案。只要您使用RequestContext,它将包含在所有模板中。

如果你真的发现工作太多,可以使用(new in 1.3)TemplateResponse class

相关问题