Always including the user in the django template context

前端 未结 8 628
一向
一向 2020-12-04 14:22

I am working on a small intranet site for a small company, where user should be able to post. I have imagined a very simple authentication mechanism where people just enter

8条回答
  •  攒了一身酷
    2020-12-04 15:15

    In a more general sense of not having to explicitly set variables in each view, it sounds like you want to look at writing your own context processor.

    From the docs:

    A context processor has a very simple interface: It's just a Python function that takes one argument, an HttpRequest object, and returns a dictionary that gets added to the template context. Each context processor must return a dictionary.

提交回复
热议问题