这是我得到的错误:视图 myapp.views.view_page 没有返回 HttpResponse 对象
谁能看到我在这里做错了什么?我似乎无法弄清楚为什么我会得到那个异常,因为我正在返回一个 HttpResponseRedirect。
视图.py
from myapp.models import Page
from django.shortcuts import render_to_response
from django.http import HttpResponseRedirect
from django.template import Template, RequestContext
from django.core.context_processors import csrf
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},context_instance=RequestContext(request))
content=page.content
return render_to_response("view.html", {"page_name" :page_name , "content" :content},context_instance=RequestContext(request))
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},context_instance=RequestContext(request))
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("/myproject/" + page_name + "/")