开发者

Changing base template based on request.user in Django

开发者 https://www.devze.com 2023-01-21 06:51 出处:网络
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

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

精彩评论

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