Hi.

You have a typo in your models.py

It should be ForeignKey not Foreignkey. Note the capital K.

6.5.2018 22.05 "Avitab Ayan Sarmah" <avitabay...@gmail.com> kirjoitti:

views.py:

from django.shortcuts import get_object_or_404, render

from . models import Question

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)

def detail(request, question_id):
question = get_object_or_404(Question, pk=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)

detail.html:

<h1>{{ question.question_text }}</h1>
<ul>
{% for choice in question.choice_set.all %}
  <li>{{ choice.choice_text }}</li>
{% endfor %}
</ul>

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 %}

mysite/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'),
]

mysite/urls.py:

from django.contrib import admin
from django.urls import include, path

urlpatterns = [
path('', include('polls.urls')),
path('admin/', admin.site.urls),
]


please check these codes and comment where i've gone wrong

-- 
You received this message because you are subscribed to the Google Groups
"Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-developers/935bc46e-469f-4a60-882c-8c8c32cc85fe%40googlegroups.com
<https://groups.google.com/d/msgid/django-developers/935bc46e-469f-4a60-882c-8c8c32cc85fe%40googlegroups.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAHn91ocKh8G3NYAxDoa_57fHNKjdSHqZK6UBCydB3YrvbNf3Lg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to