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