我尝试使用 django 在另一个模板中包含一个模板,如果我包含的模板没有变量,则一切正常,但是当模板有变量时,例如 {{form}} 不会渲染变量,但渲染模板:
浏览次数:
class IdentifiacionsUsuariosView(FormView):
form_class = FormProductores
success_url = '/'
template_name = 'propietarios.html'
def form_valid(self,form):
productor = form.save()
return super(IdentifiacionsUsuariosView,self).form_valid(form)
模板-1.html
Hello
<form action="." method="POST">{% csrf_token %}
{{form}}
<p><input type="submit" value="ok"></p>
</form>
模板-2.html
<div class="span4" id="campo1">
{% include 'template-1.html' %}
</div>
像这样,我看到“你好”和提交输入,但我无法渲染表单,我该怎么做?
最佳答案
https://docs.djangoproject.com/en/1.8/topics/forms/#reusable-form-templates
在代码中引用模板。
{% include "template-1.html" %}
If the form object passed to a template has a different name within the context, you can alias it using the with argument of the include tag:
{% include "form_snippet.html" with form=comment_form %}
关于django - 在表单中包含标签 django,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29666067/