If you are simply adding something to most every request, I would add a context processor in the TEMPLATE settings.
Check out
https://docs.djangoproject.com/en/2.1/topics/templates/#context-processors
In this example, I have an app called general. Within that is a py file called context_processors. In that file is a function called extra_context that takes request as an argument. I just return a dictionary that all of my templates have access to.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
os.path.join(BASE_DIR, 'templates'),
],
'APP_DIRS': True,
'OPTIONS': {
'debug': True,
'context_processors': [
# Insert your TEMPLATE_CONTEXT_PROCESSORS here or use this
# list if you haven't customized them:
'django.contrib.auth.context_processors.auth',
'django.template.context_processors.debug',
'django.template.context_processors.i18n',
'django.template.context_processors.media',
'django.template.context_processors.static',
'
django.template.context_processors.tz',
'django.contrib.messages.context_processors.messages',
'django.template.context_processors.request',
'general.context_processors.extra_context',
],
},
},
]
--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
django-users...@googlegroups.com.
To post to this group, send email to
django...@googlegroups.com.
Visit this group at
https://groups.google.com/group/django-users.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-users/CACQ%3DrrfLhhHrtKVSvcwJ7SmNyePdybEhO50%2Bepd8hcuLEG5sgg%40mail.gmail.com.
For more options, visit
https://groups.google.com/d/optout.