3👍
If you add django.core.context_processors.request
to your TEMPLATE_CONTEXT_PROCESSORS
setting, it will add the request
variable to every template-rendering that uses a RequestContext
(which is most of the built-in ones). This is the HTTPRequest
object for the current request, the path
attribute of which is the requested path. More information can be found in the docs.
- [Django]-Django.core.exceptions.ImproperlyConfigured: Requested setting INSTALLED_APPS, but settings are not configured
- [Django]-Why do chat applications have to be asynchronous?
- [Django]-How to Insert foreign key in other table using Django Rest Framework?
- [Django]-Django-like frameworks?
- [Django]-Django: Better way to aggregate QuerySet results
2👍
I ended up using this but ran into a little hiccup along the way. Here’s my solution path in the hopes that I save someone else some time.
At first I added this line to my settings.py file:
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.request",)
I found that it allowed me to access the request path from within a template which had been passed a RequestContext
by using the template variable {{ request.path }}
. However, it also disabled all the other context processors. To fix this I tried adding the defaults to the TEMPLATE_CONTEXT_PROCESSORS
tuple. At first this failed because I had used the context processors for Django 1.2 (I have Django 1.1 installed). After fixing that problem I was left with the following settings file:
TEMPLATE_CONTEXT_PROCESSORS = ("django.core.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.request",
)
- [Django]-Django: filter queryset when 2 fields have same value
- [Django]-Django next page not working in login page
- [Django]-Django-extensions: Run a script using runscript which is inside a folder within scripts