Sure:
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list = Question.objects.order_by('-pub_date')[:5]
output = ', '.join([q.question_text for q in latest_question_list])
return HttpResponse(output)
def detail(request, question_id):
return HttpResponse("You're looking at question %s." % question_id)
def results(request, question_id):
response = "You're looking at the results of question %s."
return HttpResponse(response % question_id)
def vote(request, question_id):
return HttpResponse("You're voting on question %s." % question_id)
As a matter of advice, please use a fixed-width font when pasting code, because Python is indented with spaces and using any other type of font makes reading your mail difficult :)
El jue., 3 may. 2018 a las 18:08, Avitab Ayan Sarmah (<avitabayans@gmail.com>) escribió:
hello Fidel Leon can you please rewrite the whole views.py code so that i can understand what is the exact code is--On Thu, May 3, 2018 at 9:19 PM, Fidel Leon <fidel@flm.cat> wrote:--El jue., 3 may. 2018 a las 17:38, Avitab Ayan Sarmah (<avitabayans@gmail.com>) escribió:polls/views.py:from django.http import HttpResponsefrom django.template import loaderfrom . models import Questiondef index(request):return HttpResponse("Hello, world.You're at the polls index.")latest_question_list = Question.objects.order_by('-pub_date')[:5]output = ', '.join([q.question_text for q in latest_question_list])return HttpResponse(output)latest_question_list = Question.objects.order_by('-pub_date')[:5]template = loader.get_template('polls/index.html')context = {'latest_question_list': latest_question_list,}return HttpResponse(template.render(context, request))Your function index(request) inside polls/views.py is badly written (you have three function returns). Seems you are following the tutorial but not removing the previous examples:def index(request):latest_question_list = Question.objects.order_by('-pub_date')[:5]context = {'latest_question_list': latest_question_list}return render(request, 'polls/index.html', context)--Fidel Leon
You received this message because you are subscribed to a topic in the Google Groups "Django users" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/django-users/5hvN4Lfds-w/unsubscribe.
To unsubscribe from this group and all its topics, 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/CAHXg%3DN2SNuyAsAzk7mYfBB5rahtD3fRSa4vTbL92BQf5CHg-Nw%40mail.gmail.com.
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/CAEx5wm7VMMa3C2%3DyWA%3DQu%3DhihJiWujwvoA59Xx4ru59Zdc0UVg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
Fidel Leon
Phone: +34 622 26 44 92
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/CAHXg%3DN3-8kKboqLD8cFRympuLvtTgj0uh6BxbfMr8FtfyNEojA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment