okay
On Thursday, May 3, 2018 at 10:37:47 AM UTC-5, Avitab Ayan Sarmah wrote:
-- On Thursday, May 3, 2018 at 10:37:47 AM UTC-5, Avitab Ayan Sarmah wrote:
mysite/urls.py:from django.contrib import adminfrom django.urls import include, pathurlpatterns = [path('', include('polls.urls')),path('admin/', admin.site.urls),]polls/templates/polls/index.html :{% if latest_question_list %}<ul>{% for question in latest_question_list %}<li><a href="/polls/{{ question.id }}/">{{question.question_text }}</a></li>{% endfor %}</ul>{% else %}<p>No polls are available.</p>{% endif %}polls/urls.py:from django.urls import pathfrom . import viewsurlpatterns = [# 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'),]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)) 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)i've attached the command prompt below.Please check,your help would be very helpfull
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/38e201a2-49f4-480a-b9f2-fa49f5622c22%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
No comments:
Post a Comment