Code to run on every view

Hello,

I have a navigation menu, with certain entries that should only be displayed if the current user has some specific permissions.

I am using a base template, that contains the navigation menu, and it works well enough.

Now, I don’t want to write for each view, to update this menu, so I can write a function, and call this function in each view. Is this the best way ?

Thanks for your help.

I would look at writing a custom context processor for that, which will save you from repeating code in all your views and automatically make whatever navigation context you need available to all templates.

1 Like