Thursday, 30 May 2013

Django - Access HttpRequest from Template

settings.py
TEMPLATE_CONTEXT_PROCESSORS = (
    ....
    'django.core.context_processors.request', # not enabled by default
    ....
)
template.html
{{ request.GET.foo }} {{ request.COOKIES }} {{ request.META }} {{  request.user }}
# To access current HttpRequest's attributes & methods

More Info:
https://docs.djangoproject.com/en/dev/ref/templates/api/#django-core-context-processors-request
https://code.djangoproject.com/wiki/HttpRequest

No comments :

Post a Comment