来自views.py的代码:
def feedback(request):
if request.method == "POST":
form = CommentForm(request.POST)
if form.is_valid():
form.save()
else:
print("form.errors:", form.errors)
else:
form = CommentForm()
articles = Comment.objects.all()
ResponseDict = {"articles": articles, "form": form}
return render_to_response("feedback.html", ResponseDict,
context_instance = RequestContext(request))
我已经尝试过这个以及对类似问题的答案的一些修改,但没有任何效果。当我按下提交按钮时,html 中的所有表单字段都变为空。
编辑:来自feedback.html的代码:
{% extends "base.html" %}
{% block main %}
<table>
<form action="/feedback/" method="POST">
{% csrf_token %}
<div class="article">
<label for="name">
Ваше имя:
</label>
<br />
<input type="text" name="name" id="name" size="40" class="inputbox" value="" />
<br />
<!-- class="inputbox required" -->
<textarea class="WithoutTinymce" cols="50" rows="10" name="text" id="text"></textarea>
<br />
<input type="submit" name="submit" value="Отправить">
</div> <!-- /article -->
</form>
</table>
{% include "articles.html" %}
{% endblock %}
如果需要,我还可以从 base.html 粘贴代码。
EDIT2:base.html 中的最小化代码:
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="cs" lang="cs">
...
<body id="body-id" onload="loaded()">
<!-- Main -->
<div id="main" class="box">
<div id="page" class="box">
<div id="page-in" class="box">
<!-- Content -->
<div id="content">
{% block main %}
{% endblock %}
<hr class="noscreen" />
</div> <!-- /content -->
</div> <!-- /page-in -->
</div> <!-- /page -->
</div> <!-- /Main -->
</body>
</html>