[英]How to work with this form in Django?
Normally when I want to display individual form fields I use: 通常,当我想显示单个表单字段时,我使用:
{{ form.NAMEOFFIELD }}
and if I want to display the entire form I just do: 如果我想显示整个表格,我只是这样做:
{{ form }}
But now I'm working on a file where that doesn't work. 但是现在我正在处理一个不起作用的文件。 The backend developers might not have made the form view specific so the only way I can display it is by doing:
后端开发人员可能没有使表单视图特定,所以我可以显示它的唯一方法是:
{% render_comment_form for object.video %}
For this form, how can I grab individual field and catch form errors (since it's not called the usual way)? 对于这种形式,我如何获取单个字段并捕获表单错误(因为它不是通常的方式)?
Presumably you're talking about the comments app. 大概是你在谈论评论应用程序。 As well as
render_comment_form
, that app provides a get_comment_form
tag: 除了
render_comment_form
,该应用程序还提供了get_comment_form
标记:
{% get_comment_form for object.video as comment_form %}
Now the form is available in the comment_form
variable, and can be iterated in the normal way. 现在表单在
comment_form
变量中可用,并且可以以正常方式迭代。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.