我在 django 教程中做 wiki,在教程中使用 django 的早期版本,其中 csrf 令牌不是强制性的。我已将 {% csrf_token %} 添加到表单中,但是我不确定在视图中要做什么。请帮忙。
这是表格:
<form method = "POST" action="/wikicamp/{{ page_name }}/save/">{% csrf_token %}
<textarea name = "content" rows="20" cols="60">{{ content }}</textarea><br/>
<input type="submit" value="Save Page"/>
</form>
视图.py:
def view_page(request, page_name):
try:
page = Page.objects.get(pk=page_name)
except Page.DoesNotExist:
return render_to_response("create.html", {"page_name" : page_name})
return render_to_response("view.html", {"page_name" : page_name,
"content" : page.content})
def edit_page(request, page_name):
c = {}
c.update(csrf(request))
try:
page = Page.objects.get(pk=page_name)
contents = page.content
except Page.DoesNotExist:
content = ""
return render_to_response("edit.html", {"page_name" : page_name,
"content" : content}, c)
def save_page(request, page_name):
content = request.POST["content"]
try:
page = Page.objects.get(pk=page_name)
page.content = content
except Page.DoesNotExist:
page = Page(name = page_name, content = content)
page.save()
return HttpResponseRedirect("/wikicamp/" + page_name + "/")
这是错误
TypeError at /wikicamp/start/edit/
pop expected at least 1 arguments, got 0