django writing custom context processor

前端 未结 1 700
难免孤独
难免孤独 2020-12-22 11:58

I\'m writing my own custom context_processor on django (1.11) and to get infos of an authenticated user from auth0. It\'s not my first time writing it and I don

相关标签:
1条回答
  • 2020-12-22 12:19

    Instead of

    'auth.context_processors.auth0_processors'
    

    give the concrete method:

    'auth.context_processors.auth0_processors.auth0_user'
    

    At least that is what the error is complaining about:

    does not define a "auth0_processors" attribute/class

    It is looking for a class or attribute, so try with the function name.

    From the documentation:

    The context_processors option is a list of callables – called context processors – that take a request object as their argument and return a dictionary of items to be merged into the context.

    In answer to your comment:

    If you always need the same objects then just create one method that adds all of the required objects to the context instead of several methods.

    EDIT:

    Also note that with 'django.template.context_processors.request' you could already have the complete request object in the context. You might not need your own context processor if you just need access to the session.

    0 讨论(0)
提交回复
热议问题