1👍
By adding django.core.context_processors.request
to your TEMPLATE_CONTEXT_PROCESSORS
(which comes by default) you should have a request
instance on the templates. You can then access the user (which may be an authenticated User
or an AnonymousUser
, never None
) on your templates by typing:
{% if request.user.is_authenticated %}
0👍
the request object itself is accessible on the html pages
better to use that in your base.html file to access it on all pages like
{% if request.user.is_authenticated %}
- [Answer]-How to asyncronously load posts from DB to django template on google app engine?
- [Answer]-Allow staff to edit email data via django admin site?
- [Answer]-Pysqlite DatabaseError: You must not use 8-bit bytestrings unless you use a text_factory
- [Answer]-Django app engine cannot import name old_dev_appserver
0👍
Am using django 1.4 and apparently request
is not a default context. Or as it is I could not access request
by default so I added this to my settings.py
and it worked for me
TEMPLATE_CONTEXT_PROCESSORS = (
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.debug",
"django.core.context_processors.i18n",
"django.core.context_processors.media",
"django.core.context_processors.static",
"django.contrib.messages.context_processors.messages",
"django.core.context_processors.request",)
Of course in my case I only needed "django.core.context_processors.request"
but since I am overriding the default context processors
, I need to add them manually in my settings
- [Answer]-Add value to database without using forms in django
- [Answer]-Django: FILES Form Not Validating