开发者

Passing request.user to template in Django

Is there another way to get the request.user b开发者_JAVA百科y not passing it from the views? I think passing request.user from all functions in views to the template is quite wrong. Is there any method or way that the template will get the user or any object in the database?


By default (I am talking about Django version 1.3) you do not need change TEMPLATE_CONTEXT_PROCESSORS. Because default value already contains *django.contrib.auth.context_processors.auth*.

So to your question: By default, you should be able to use user, messages and perms variables in your template. For example:

User: {{user.username}}
{% if perms.appname.permname %}
  ... do something usefull ...
{% endif %}


Context processors.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜