Tuesday, May 29, 2018

Re: ValueError at /polls/1/vote/

How would I apply a return for my view here?

from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from django.urls import reverse
from django.views import generic

from .models import Choice, Question


class IndexView(generic.ListView):
template_name = 'polls/index.html'
context_object_name = 'latest_question_list'

def get_queryset(self):
"""Return the last five published questions."""
return Question.objects.order_by('-pub_date')[:5]


class DetailView(generic.DetailView):
model = Question
template_name = 'polls/detail.html'


class ResultsView(generic.DetailView):
model = Question
template_name = 'polls/results.html'


def vote(request, question_id):
... # same as above, no changes needed.

On Tuesday, May 29, 2018 at 7:56:03 AM UTC-4, Julio Biason wrote:
View require that you return an HttpResponse object. Your function does not (it probably even lacks a "return").

You need to return the response back in the view.

On Tue, May 29, 2018 at 8:48 AM, Caleb Bryson <cbrys...@gmail.com> wrote:
Hey i am getting this error now can anyone help me fix this? and what code do you need to see to help out?

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/a3a72079-74a0-404f-aedd-828597090663%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--
Julio Biason, Sofware Engineer
AZION  |  Deliver. Accelerate. Protect.
Office: +55 51 3083 8101  |  Mobile: +55 51 99907 0554

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/ab1fd070-f57d-4cf2-b370-c0953c1d15fd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment