我正在使用showmedo的视频教程创建一个wiki应用程序。 从我所知的教程是旧的,我正在使用django 1.4.3
当我尝试将页面保存到wiki首页时遇到错误。
ValueError at /wikicamp/start/save/
The view wiki.views.save_page didn't return an HttpResponse object.
Request Method: GET
Request URL: http://127.0.0.1:8000/wikicamp/start/save/
Django Version: 1.4.3
Exception Type: ValueError
Exception Value:
The view wiki.views.save_page didn't return an HttpResponse object.
Exception Location: C:\Python26\Lib\site-packages\django\core\handlers\base.py in get_response, line 129
Traceback Switch to copy-and-paste view
C:\Python26\Lib\site-packages\django\core\handlers\base.py in get_response
raise ValueError("The view %s.%s didn't return an HttpResponse object." % (callback.__module__, view_name))
我认为问题出在我的views.py函数save_page
下我的观点是:
from wiki.models import Page
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
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})
content = page.content
return render_to_response("view.html",{"page_name":page_name , "content":content})
def edit_page(request,page_name):
try:
page = Page.objects.get(pk=page_name)
content = page.content
except Page.DoesNotExist:
content = ""
return render_to_response("edit.html",{"page_name":page_name, "content":content})
def save_page(request , page_name):
content = request.POST.get('content', 'this is the default')
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 + "/")
答案 0 :(得分:0)
嗯,是的,如果页面确实存在,您的save_page
视图不会返回任何内容。
您很可能只是意外地缩进了save
下的return
和except
:
def save_page(request, page_name):
content = request.POST.get('content', 'this is the default')
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 + "/")