I’m making a simple vote class, where a user can vote up or vote down an answer. I don’t want this function to return anything,as the vote for every user is created when he votes.
The problem is that my redirection, or empty return gives me an error like: The page isn’t redirecting properly from browser.
My code:
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
where am i wrong?
Thanks!
http://docs.djangoproject.com/en/1.2/ref/request-response/#django.http.HttpResponseRedirect
What makes you think ‘.’ will work?
Usually use the
reversefunction to provide the absolute URL required.http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse