擅长:python、mysql、java
<p>在我看来,你的问题就在眼前,你应该这样做:</p>
<pre><code>@login_required
def yazi_ekle(request):
yazim = YaziForm() # Look at the (), they are needed for instantiation
return render_to_response('yazi/save.html', {'YaziForm': yazim}) # Sending the form instance to the context, not the form class
</code></pre>
<p>现在,在模板上下文中有一个名为YaziForm的变量。Django forms会自动返回一堆默认为小部件的表行,因此在文件yazi/save.html中,执行以下操作</p>
<pre><code><form method="post" action="">
{% csrf_token %}
<table>
{{YaziForm}}
</table>
<input type="submit" value="Submit Form"/>
</form>
</code></pre>
<p>这将自动将窗体呈现为表,尽管您必须在POST下添加窗体的逻辑。</p>