Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django request in template

Tags:

I've enabled the django request processor

TEMPLATE_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", ) 

Still i don't have to request variable available in templates. I've to manually pass it. Using django 1.0.2 Everywhere on web it seems it's only about enabled request processor..

Also i am using RequestContext as :

 return render_to_response(     'profile.html',     {         'persons':Person.objects.all(),         'person':Person.objects.get(id=id),          'request':request,     },     context_instance=RequestContext(request) ) 

no luck

ohh darn the new name for that is TEMPLATE_CONTEXT_PROCESSORS

like image 825
Attila Avatar asked Mar 31 '09 19:03

Attila


People also ask

What does {{ name }} this mean in Django templates?

What does {{ name }} this mean in Django Templates? {{ name }} will be the output. It will be displayed as name in HTML. The name will be replaced with values of Python variable.

What is request context in Django?

Context, but Django also comes with a subclass, django. template. RequestContext, that acts slightly differently. RequestContext adds a bunch of variables to your template context by default – things like the HttpRequest object or information about the currently logged-in user.

How a request is processed in Django?

Whenever a request comes into Django, it is handled by middlewares. When the Django server starts, the first thing it loads after settings.py is middlewares. The Request is processed by various middlewares one at a time. So, from the above list, when the request comes it will be passed through the security middleware.


2 Answers

settings.py:

TEMPLATE_CONTEXT_PROCESSORS = (   # ...   'django.core.context_processors.request',   # ... ) 
like image 73
Dingo Avatar answered Oct 21 '22 17:10

Dingo


TEMPLATE_CONTEXT_PROCESSORS instead of TEMPLATE_PROCESSORS

like image 32
Attila Avatar answered Oct 21 '22 18:10

Attila