ValueError at /blog/1/comment/new/
The view blog.views.comment_new didn't return an HttpResponse object. It returned None instead.
Request Method: GET
Request URL: http://localhost:8000/blog/1/comment/new/
爲什麼請求方法得到?Django沒有返回HttpResponse對象錯誤?
HTML
<form action="" method="post">
{% csrf_token %}
<table>
{{ form.as_table }}
</table>
<input type="submit" />
</form>
VIEWS
@login_required
def comment_new(request, post_pk):
post = get_object_or_404(Post, pk=post_pk)
if request.method == 'post':
form = CommentForm(request.POST)
if form.is_valid():
comment = form.save(commit=False)
comment.post = post
comment.author = request.user
comment.save()
return redirect('blog:post_detail', post.pk)
else:
form = CommentForm()
return render(request, 'blog/comment_form.html', {
'form': form,
})`
感謝
爲什麼你沒有在html表單中指定任何操作參數 –
我現在不需要參數。 –
你應該指定一個動作url,否則你將如何確保沒有額外的混亂被髮送到服務器 –