开发者

Changing base template based on request.user in Django

I want to modify part of my base navigation menu based on a flag on the user model, without having to include request.user in every single view function in my codebase. The nav menu is part of the base template which every other template extends.

Is there a simple way to do this (if so, I suck at search)? 开发者_开发知识库If not, is there a standard workaround?


If I understand you correctly:

{% if request.user.flag %}
    {% include "nav1.html" %}
{% else %}
    {% include "nav2.html" %}
{% endif %}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜