Always including the user in the django template context

前端 未结 8 647
一向
一向 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:18

    Use context_processors. https://docs.djangoproject.com/en/2.2/ref/settings/#std:setting-TEMPLATES-OPTIONS

    settings.py

    'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'myapp.functions.test'
            ],
    },
    

    myapp/functions.py

    def test(request):
        return {'misc': 'misc'}
    

提交回复
热议问题