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 %}
精彩评论