46👍
✅
settings.py:
TEMPLATE_CONTEXT_PROCESSORS = (
# ...
'django.core.context_processors.request',
# ...
)
- [Django]-Change list display link in django admin
- [Django]-Problems with contenttypes when loading a fixture in Django
- [Django]-Django Query Related Field Count
8👍
Be advised that as of Django 1.8, this has changed to a “TEMPLATES” setting, and in the default configuration, the request processor is NOT included.
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [
# insert your TEMPLATE_DIRS here
],
'APP_DIRS': True,
'OPTIONS': {
'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',
],
},
},]
Just add the request processor back in to fix the issue:
'django.core.context_processors.request',
For more info, see the Django Upgrading Docs.
- [Django]-Django REST Framework: 'BasePermissionMetaclass' object is not iterable
- [Django]-Circular dependency in serializers
- [Django]-Get object by field other than primary key
1👍
Are you sure you don’t have the request
variable available to the template? What happens when you remove the line
'request':request,
that’s different from when that line is present. If your template loads the same either way, the problem is with your template.
- [Django]-Favorite Django Tips & Features?
- [Django]-Django 1.7 migrations — how do I clear all migrations and start over from scratch?
- [Django]-Django 1.11 Annotating a Subquery Aggregate
0👍
MIDDLEWARE_CLASSES=(
…
‘yourfolder.yourfile.yourclass’,
…
yourclass:
class AddRequestToTemplate:
process_templaet_response(self, request, response):
response.context_data[‘request’]=request
- [Django]-Where can I download the Django documentation?
- [Django]-ImportError: bad magic number in 'time': b'\x03\xf3\r\n' in Django
- [Django]-Django FileField: How to return filename only (in template)
Source:stackexchange.com