0
我在Django中有模板标签用法问题。让我定义我的html和模板标签。表单元素的Django模板标签
photo_detail.html
{% for photo in pList %}
{% getFormElements form photo.pk %}
{{ caption_field }}
{{ city_field }}
{%endfor %}
photohelper.py
from django import template
register = template.Library()
@register.inclusion_tag('wpphotos/post/photo_detail.html')
def getFormElements(form,pid):
return {'caption_field':form.fields['caption_%s' % pid],'country_field':form.fields['country_%s' % pid],'city_field':form.fields['city_%s' % pid] }
我的形式具有诸如
caption_1
city_1
country_1
caption_2
city_2
country_2
我想要做的是分组caption,country and city
通过照片ID,而渲染这些领域。
我试图说明我的目标在上面的代码,但它不起作用。
我该如何实现这一目标?
谢谢
是的你是对的谢谢! – brsbilgic