Hi ,
-- While try to execute it showing AttributeError, Can some one help me on this.
My views.py
from django.shortcuts import render
from django.http import Http404
from django.http import HttpResponse
from .models import Question
def index(request):
latest_question_list=Question.objects.order_by('pub_date')[:3]
context={'latest_question_list':latest_question_list}
return render(request,'polls/index.html',context)
def detail(request, question_id):
try:
question=Question.object.get(pk=question_id)
except Question.DoesNotExist:
raise Http404("Question does not exist")
return render(request, 'polls/detail.html', {'question':question})
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)
My detail.html
{{question}}
My polls/urls.py
from django.urls import path
from . import views
urlpatterns = [
# ex: /polls/
path('', views.index, name='index'),
# ex: /polls/5/
path('<int:question_id>/', views.detail, name='detail'),
# ex: /polls/5/results/
path('<int:question_id>/results/', views.results, name='results'),
# ex: /polls/5/vote/
path('<int:question_id>/vote/', views.vote, name='vote'),
]
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 view this discussion on the web visit https://groups.google.com/d/msgid/django-users/9918df61-41fd-40bd-8ca3-79ee3be12ec3%40googlegroups.com.
No comments:
Post a Comment