Sunday, May 6, 2018

Re: While going through django tutorial i found some errors when i tried to execute the python manage.py runserver.The error is attached below:

It is ForeignKey (capital K).

In your files you sent you missed the one file it was actually
complaining about :



On 06/05/18 18:09, Avitab Ayan Sarmah wrote:
> 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 %}
>
> admin.py:
>
>
> from django.contrib import admin
>
> from . models import Question
>
> admin.site.register(Question)
>
> 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>
>
> 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 the above codes and comment where i've gone wrong
> --
> 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
> <mailto:django-users+unsubscribe@googlegroups.com>.
> To post to this group, send email to django-users@googlegroups.com
> <mailto: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/12b0418f-7979-4d07-b827-68b0c2aaaa27%40googlegroups.com
> <https://groups.google.com/d/msgid/django-users/12b0418f-7979-4d07-b827-68b0c2aaaa27%40googlegroups.com?utm_medium=email&utm_source=footer>.
> For more options, visit https://groups.google.com/d/optout.


--
--
Anthony Flury
email : *Anthony.flury@btinternet.com*
Twitter : *@TonyFlury <https://twitter.com/TonyFlury/>*

--
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/420f69c9-717a-a9c5-9196-3165418c25d0%40btinternet.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment