Dynamic user menu in Django

Is there a way to change the user menu according to the permissions assigned to the user group to which the user belongs? I think that it checks these permissions at the presentation level, and also removes menu options that the user does not have permission to.

+4
source share
2 answers

Yes, you can access the user object in the template and check if the user is like this:

{% if user.is_staff %} <li> <a href="/admin/">Admin</a> </li> {% endif %} 

This will be an example where your menu contains links to links. Admin link will be displayed only for users with is_staff status. You can do the same with is_authenticated.

Django is designed to separate the logic from the presentation, so if you want to have even finer control over the menu, I would suggest making the logic inside the view and then setting a variable that you can check in the template to determine which menu to show.

+9
source

For the most part, the django admin no longer provides you with links to what you cannot do.

Django Grappelli (and Django is the skin administrator) implements some sort of bookmarking if that’s what you mean http://code.google.com/p/django-grappelli/

+2
source

All Articles