Monday, May 28, 2018

Re: Having trouble loading up my poll app

P.S.: This is my first attempt at setting up a website using django so my code may look a little ruff.

here is my urls.py
from django.urls import path

from . import views

urlpatterns = [
path('', views.index, name='index'),

path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
]

app_name = 'polls'
urlpatterns = [
path('', views.index, name='index'),
path('<int:question_id>/', views.detail, name='detail'),
path('<int:question_id>/results/', views.results, name='results'),
path('<int:question_id>/vote/', views.vote, name='vote'),
]

here is my detail.html 
<h1>{{ question.question_text }}</h1>

{% if error_message %}<p><strong>{{ error_message }}</strong></p>{% endif %}

<form action="{% url 'polls:vote' question.id %}" method="post">
{% csrf_token %}
{% for choice in question.choice_set.all %}
<input type="radio" name="choice" id="choice{{ forloop.counter }}" value="{{ choice.id }}" />
<label for="choice{{ forloop.counter }}">{{ choice.choice_text }}</label><br />
{% endfor %}
<input type="submit" value="Vote" />
</form>

and here is my result.html
<h1>{{ question.question_text }}</h1>

<ul>
{% for choice in question.choice_set.all %}
<li>{{ choice.choice_text }} -- {{ choice.votes }} vote{{ choice.votes|pluralize }}</li>
{% endfor %}
</ul>

<a href="{% url 'polls:detail' question.id %}">Vote again?</a>

On Monday, May 28, 2018 at 9:45:41 PM UTC-4, Caleb Bryson wrote:
Hey guys, I am on part 4 of writing your first django app. And I am stuck at the part where it says this "Now, go to /polls/1/ in your browser and vote in the question. You should see a results page that gets updated each time you vote. If you submit the form without having chosen a choice, you should see the error message." . I thought I was supposed to use the url "http://localhost:8000/polls/1/" but it gave me a error saying "Template does not exist at /polls/1/". I am not really sure how to fix this to move on with the tutorial. Does anyone know how to get rid of this error?

--
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/a940e7c2-24ed-4412-8424-eff83beaf421%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment