【发布时间】:2017-03-22 12:02:14
【问题描述】:
如果你有多个表格
from django import forms
class NameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
class SecondNameForm(forms.Form):
your_name = forms.CharField(label='Your name', max_length=100)
有没有一种方法可以在您的模板中确定context 内部的form 是否属于NameForm 或SecondNameForm
我有一个自定义小部件,在其 html 中,它使用 id="" 标识符(在整个 html 中应该是唯一的)。
我想将 id 分配给类似的东西
id="{{form.name}}_{{field.val}}" 或
id="{{form.id}}_{{field.val}}" 或
其中{{form.name}} 和{{form.id}} 是与表单实例相关联的某个值,而不是与表单内容相关联的值。
【问题讨论】:
标签: django django-forms django-templates