Django,表单字段的唯一ID
我有一个简单的Django表单:
I have a simple Django form:
class CommentForm(forms.Form):
comment = forms.CharField(max_length=2000, required=True)
post_id = forms.CharField(max_length=2000, widget=forms.HiddenInput, required=True)
parent_id = forms.CharField(max_length=2000, widget=forms.HiddenInput, required=True)
现在我要在我的页面上打印此表单多次 - 我通过一个模板标签来做,所以每次都创建新的表单。问题是,我得到所有字段的相同的ID。
Now I want to print this form several times on my page - I am doing it through a template tag, so the new form is created each time. The problem is, that I get the same ID's for all fields.
我知道前缀,但我不想更改字段名称,因为有一个处理程序对于所有表单,只能设置唯一的ID。
I know about the prefix, but I do not want to change field names, because there is one handler for all forms, only to set unique IDs.
所以我的问题:
- 有没有办法使Django设置唯一的ID,如果我想输出一个表单多次,而不更改字段的名称?
- 如果没有,有没有办法使Django不输出ID?
您可以控制自动ID的生成方式 auto_id 参数当您创建该表单的新实例
You can control how the automatic IDs are generated with the auto_id parameter when you create a new instance of that form
查看此处(搜索 auto_id ):
http://docs.djangoproject.com/en/dev/ref/forms/api/#configuring-html-label-tags