Sunday, November 22, 2015

Re: List of available Jinja2 global symbols

I don't believe there's a list in the documentation, but you can get them from the source code at https://github.com/django/django/blob/master/django/template/backends/jinja2.py#L66:

if request is not None:
    context
['request'] = request
    context
['csrf_input'] = csrf_input_lazy(request)
    context
['csrf_token'] = csrf_token_lazy(request)

On Sunday, November 22, 2015 at 1:17:59 PM UTC+1, JirkaV wrote:
Hi there, I'm not a Jinja2 user, but standard Django templates get these variables via context processors‎. Check out https://docs.djangoproject.com/en/1.8/topics/templates/#context-processors

 HTH

   Jirka

From: Patrick Spencer
Sent: neděle, 22. listopadu 2015 5:45
To: Django users
Subject: List of available Jinja2 global symbols

I'm using Django 1.8.6 with the built in JInja2 support. I spent a while trying to figure out how to pass a csrf token to a JInja2 template. After a while I realized one could just write {{ csrf_token }} in the template, without passing this value through a view, and it would just print out the token. I also realized you could reference a request object without passing it through the view i.e. {{ request.user }} returns the current user. Is there a place in the documentation with all the available global symbols one can use in a Jinja2 template?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/537bd366-180e-4876-8b91-5791f8e22d44%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/3841c96b-9adc-465a-8a8a-a611571b792a%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment