开发者

Passing context between templatetags, django

开发者 https://www.devze.com 2022-12-24 08:09 出处:网络
I am using django to create a web-application. I have created a template in where I load a templatetag. In this templatetag I load another templatetag. From the template I pass context to the first t

I am using django to create a web-application.

I have created a template in where I load a templatetag. In this templatetag I load another templatetag. From the template I pass context to the first templatetag, but the开发者_Go百科 context is not available from the second templatetag (inside the first templatetag) - see below.

I hope this makes sense, and that one of you have the answer.


Template snippit:

{% load templatetags %}
{% some_tag argument %}

some_tag Templatetag:

{% load templatetags %}
{% some_other_tag another_argument %}

some_other_tag Templatetag:

In this templatetag I am trying to access context to get user info i.e. using

request = context['request']
request.user


Don't forget that the context to the subtemplate - and hence to the second template tag - is whatever is returned from the first template tag function. So you'll need to ensure that the request object is included in the dictionary you return there.

0

精彩评论

暂无评论...
验证码 换一张
取 消