我做了一个简单的投票类,用户可以投票支持或否决答案。我不希望这个函数返回任何东西,因为每个用户的投票都是在他投票时创建的。问题是,我的重定向或空返回会给我一个错误,比如:页面没有从浏览器正确地重定向。
我的代码:
def vote_answer_down(request,id):
answer = Answer.objects.get(pk = id)
VoteDownAnswer.objects.create(answer = answer, voted_down_by = request.user)
return HttpResponseRedirect('.') #or return (without httpresponse),gives the same我哪里错了?谢谢!
发布于 2010-07-01 04:48:45
http://docs.djangoproject.com/en/1.2/ref/request-response/#django.http.HttpResponseRedirect
构造函数只接受一个参数--要重定向到的路径。这可以是完全限定的网址(例如'http://www.yahoo.com/search/'),也可以是没有域的绝对网址(例如'/search/')。请注意,这将返回HTTP状态代码302。
是什么让你觉得“.”会起作用吗?
通常使用reverse函数来提供所需的绝对网址。
http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse
https://stackoverflow.com/questions/3153157
复制相似问题