使用crispy_forms时,是什么控制了表单名称参数?

时间:2021-07-12 15:59:23

Looking at the documentation, I see that the proper way to render a crispy form is simply

看一下文档,我看到渲染一个脆的形式的正确方法很简单

{% crispy form %}

However, later on the page it suggests that the user can render multiple forms using

但是,稍后在页面上它表明用户可以使用呈现多个表单

{% crispy form_1 %}
{% crispy form_2 %}

Where do I define form_1 and form_2? (The form? The view?) I don't see those anywhere in the sample code.

我在哪里定义form_1和form_2? (表单?视图?)我没有在示例代码中看到任何地方。

1 个解决方案

#1


1  

These names are the template context variables which are passed in the view to the render() function:

这些名称是模板上下文变量,它们在视图中传递给render()函数:

return render(request, 'my_form.html', {'form': form})

return render(request, 'my_form.html', {'form': my_form})

return render(request, 'my_form.html', {'form_1': form1, 'form_2': form2})

return render(request, 'my_form.html', {'form_1': first_form,
                                        'form_2': second_form})

#1


1  

These names are the template context variables which are passed in the view to the render() function:

这些名称是模板上下文变量,它们在视图中传递给render()函数:

return render(request, 'my_form.html', {'form': form})

return render(request, 'my_form.html', {'form': my_form})

return render(request, 'my_form.html', {'form_1': form1, 'form_2': form2})

return render(request, 'my_form.html', {'form_1': first_form,
                                        'form_2': second_form})