开发者

using returned value of templatetags by aliasing in django

开发者 https://www.devze.com 2023-03-18 03:59 出处:网络
Is there any way to use the return element of templatetags by aliasing ? For example, templatetags.py开发者_开发知识库

Is there any way to use the return element of templatetags by aliasing ?

For example,

templatetags.py开发者_开发知识库

@register.simple_tag()
def getCaptionLabel(form,pid):
    return form.__getitem__('caption_%s'%pid)

mypage.html

{% with field = getCaption form photo.pk %}

{{ field.label_tag }}


No, you have to actually do it in your tag. The Django trunk now has an assignment_tag (See: https://docs.djangoproject.com/en/dev/howto/custom-template-tags/#assignment-tags) to allow you to do this easily, but until it hits a release, you'll have to do it the old fashioned way. See: https://docs.djangoproject.com/en/1.3/howto/custom-template-tags/#setting-a-variable-in-the-context

0

精彩评论

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