Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 1086379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T22:48:21+00:00 2026-05-16T22:48:21+00:00

Does anyone know a good way to solve this other problem I have. My

  • 0

Does anyone know a good way to solve this other problem I have. My site shows menus based on a users privs. I have a function that returns the privs as a dictionary as below:

return {"manage_entries":True, "manage_members":False, 
   "manage_something_else":True}

I passed in each priv to my base template that includes the navigation bar and use simple {% if priv %} to decide if I am going to show the menu item or not. It works fine except…

I need to pass the privs in the context of every view as they all include the base.html template and thus menu. There are lots of views so this is stupid. There must be a better way!

Cheers

Rich

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T22:48:21+00:00Added an answer on May 16, 2026 at 10:48 pm

    One way to do this is to write a simple custom template context processor. This is as simple as a function that accepts an instance of HttpRequest and returns a dictionary. In your case the dictionary can contain a list of the privileges for the current user.

    For e.g.

    # This is our processor. 
    def append_privileges(request):
        privileges = get_privs(request.user)
        return dict(privileges = privileges)
    

    Where get_privs is the method that will return the dictionary of privileges as you have indicated in your question.

    Now add this processor to the TEMPLATE_CONTEXT_PROCESSORS setting in your settings.py. Generally this variable is not present in settings. When you add it, make sure that you copy the existing default and then append to it. For e.g.

    TEMPLATE_CONTEXT_PROCESSORS = (
        # copied from docs.
        "django.contrib.auth.context_processors.auth",
        "django.core.context_processors.debug",
        "django.core.context_processors.i18n",
        "django.core.context_processors.media",
        "django.contrib.messages.context_processors.messages",
    
        # appended custom value
        "app.utils.append_privileges",
    )
    

    Finally in your base template expect the privileges variable.

    # I've added a pprint to test. You'll obviously need to do more. 
    {{ privileges|pprint }}
    

    This will make sure that all your views will automatically return a context with a correct privileges variable.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Does anyone know good way to profile a sorting algorithm in java(sequential and fork
Does anyone know a good way to cache a collection of objects returned by
Does anyone know a good way to fire a callback function on the slideUp
My java program writes information on PDF form. Does anyone know a good way
Good afternoon, Does anyone know of an out-of-the-box implementation of Levenshtein DFA ( deterministic
I have a function that I want to be able to allow passing in
Although Github provides a nice home for Java open source projects, there are some
I need to use one Service Provider with multiple identity providers(idps) each idp is
I'm working on a music related website, and frequently use the HTML special characters
I'm working with Microsft Office Interop API. My question pertains to Excel. I wrote

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.