# Polls Tutorial Not Found Error

**URL:** <https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175>\
**Category:** Using Django\
**Created:** [September 3, 2020, 5:07pm UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175 "2020-09-03T17:07:00Z")\
**Posts on this page:** 17\
**Page:** 1

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 3, 2020, 5:07pm UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/1 "2020-09-03T17:07:00Z")

</div>

Hi,

I can’t view any of the changes I’ve made in the Python files, whenever I click on a link I get ‘The requested resource was not found on this server.’

The only two links I can get to are localhost:8000/polls and localhost:8000/admin and localhost:8000/polls/1/results - but I can’t get to the index or detail or vote page.

Thanks for any suggestions.

Lisa

---

<div class="post-metadata">

**Author:** ![Suttonium](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/suttonium/32/1264_2.png) [@Suttonium](https://forum.djangoproject.com/u/Suttonium)\
**Post date:** [September 3, 2020, 6:10pm UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/2 "2020-09-03T18:10:57Z")

</div>

We’re going to need to see the files you’re using, specifically your project level and application level urls.py files, your view files, and maybe the template files you’re trying to load.

When you post them, be sure to surround the code blocks in ``` so it’s easy to read on the forum 🙂

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 6:15am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/3 "2020-09-04T06:15:01Z")

</div>

project level urls.py:

```auto
from django.urls import include, path

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

```

App level urls:

```auto
from django.urls import path

from . import views

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

```

views.py:

```auto
from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render, get_object_or_404
from django.urls import reverse

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)
    return render(request, 'polls/detail.html', {'question': question})

def results(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    return render(request, 'polls/results.html', {'question': question})

def vote(request, question_id):
    question = get_object_or_404(Question, pk=question_id)
    try:
        selected_choice = question.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        return render(request, 'polls/details.html', {
            'question': question,
            'error_message': "You didn't select a choice.",
        })
    else:
        selected_choice.votes += 1
        selected_choice.save()
        return HttpResponseRedirect(reverse('polls:results', args=(question.id,)))

```

templates - detail (not working):

```auto
<!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Details</title>
    </head>
    <body>
        <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>
    </body>
</html>

```

templates - results (working):

```auto
 <!DOCTYPE html>
<html>
    <head>
        <meta charset="UTF-8">
        <title>Polls App</title>
    </head>
    <body>
        <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>
    </body>
</html>

```

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 6:21am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/4 "2020-09-04T06:21:32Z")

</div>

I’m in the middle of page 4, where we’re about to change the redundant bits of code.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:27am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/5 "2020-09-04T06:27:56Z")

</div>

> [@LisaLaw](#):
>
> `<a href="{% url 'polls:detail' question.id %">`

At a minimum, you appear to be missing the close brace in the statement above - it should be:  
`<a href="{% url 'polls:detail' question.id %}">`

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:29am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/6 "2020-09-04T06:29:26Z")

</div>

> [@LisaLaw](#):
>
> ` {% endfor &}`

You have a syntax error in the above, it should be:  
` {% endfor %}`

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:32am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/7 "2020-09-04T06:32:41Z")

</div>

When you’re trying to mark off chunks of code, make sure you’re using the backtick - ` and not the apostrophe - it looks like you’ve got some lines of ‘’’, rather than ```.

Also, those lines of ``` need to be lines of their own. They shouldn’t be on a line with any other text.

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 6:43am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/8 "2020-09-04T06:43:29Z")

</div>

Thanks for your help Ken. I’ve fixed the syntax errors in my code, still nothing.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:45am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/9 "2020-09-04T06:45:51Z")

</div>

Can you be more specific as to which links on which page are failing? It would help me focus in on the right section of your code.

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 6:48am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/10 "2020-09-04T06:48:53Z")

</div>

Failing:  
[http://localhost:8000/index/](http://localhost:8000/index/) , …polls/1/detail/ , …/vote/

Working:  
[http://localhost:8000/polls/](http://localhost:8000/polls/) ,… /1/results/ and also /admin/

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:49am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/11 "2020-09-04T06:49:23Z")

</div>

I’m not sure if this is actually going to cause a problem, but you have a space between the word `choice` and the two open-braces in the line below.

> [@LisaLaw](#):
>
> ` <label for="choice {{ forloop.counter }}">`

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 6:54am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/12 "2020-09-04T06:54:50Z")

</div>

Ok, so I don’t see any url entry for `/index/`, so I wouldn’t expect that to work.

Your index page would just be `/polls/`.

Likewise, there’s no entry for a url `/detail/`, it’s just `/polls/1/`.

Finally, there’s no url entry for `/vote/`, it would be something like `/polls/1/vote/`

When you’re defining a name for a url, that’s an “internal-to-the-server” name, _not_ part of the url visible to the user. The url is constructed only from the components identified in the first parameter.

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 8:05am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/13 "2020-09-04T08:05:36Z")

</div>

Which file are we talking about?

> Ok, so I don’t see any url entry for `/index/` , so I wouldn’t expect that to work.

Polls urls.py:

```auto
path('', views.index, name='index'),

```

> Likewise, there’s no entry for a url /detail/, it’s just /polls/1/.

This is definitively what the tutorial said to do, surprised me too. I changed it, still nothing.

> Finally, there’s no url entry for `/vote/` , it would be something like `/polls/1/vote/`

Even when I try to put in /polls/1/vote nothing comes up. Sometimes I get a 505 error but I haven’t figured out when and why.

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 8:06am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/14 "2020-09-04T08:06:59Z")

</div>

Also I don’t understand why the polls/1/results/ page **does** work.

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 8:09am UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/15 "2020-09-04T08:09:11Z")

</div>

Edit - the detail page now works too… Really confused by this.

```auto
path('<int:question_id>/detail/', views.detail, name='detail'),

```

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [September 4, 2020, 1:52pm UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/17 "2020-09-04T13:52:11Z")

</div>

> [@LisaLaw](#):
>
> Which file are we talking about?
> 
> > Ok, so I don’t see any url entry for `/index/` , so I wouldn’t expect that to work.
> 
> Polls urls.py:
> 
> ```auto
> path('', views.index, name='index'),
> 
> ```

**This** is what I’m referring to when I said:

> [@KenWhitesell](#):
>
> When you’re defining a name for a url, that’s an “internal-to-the-server” name, _not_ part of the url visible to the user. The url is constructed only from the components identified in the first parameter.

So let’s look at this a little more closely.

You have:

```auto
path('', views.index, name='index'),

```

That’s 3 parameters you’re passing to the path function:

1. An empty string - **that’s** the url you use to access this view
2. The name of the view. (The index method in the views module - views.py)
3. name=‘index’ - _This_ is an _internal_ name for this path, **not** a part of the url.

Additionally, since you have the line:

> [@LisaLaw](#):
>
> ```auto
> path('polls/', include('polls.urls')),
> 
> ```

In your root urls file, this means that every url in your polls app will start with `polls/`

> [@LisaLaw](#):
>
> `path('<int:question_id>/detail/', views.detail, name='detail'),`

So, since all urls in the polls app starts with `polls/`, then the full path `polls/1/detail/` matches the above defined url. It’s your specification of `detail/` in that first parameter that provides the definition, _not_ the `name='detail'` parameter.

> [@LisaLaw](#):
>
> Even when I try to put in /polls/1/vote nothing comes up.

Correct - your urls entry is:

> [@LisaLaw](#):
>
> `path('<int:question_id>/vote/', views.vote, name='vote'),`

Which shows a trailing `/` after the word vote.  
Using `/polls/1/vote` isn’t going to work because you didn’t supply the trailing `/`.

We’ve covered a lot of ground here - which is good, If you still have questions or are still seeing something, please feel free to continue asking here.

Ken

---

<div class="post-metadata">

**Author:** ![LisaLaw](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/lisalaw/32/1999_2.png) [@LisaLaw](https://forum.djangoproject.com/u/LisaLaw)\
**Post date:** [September 4, 2020, 3:34pm UTC](https://forum.djangoproject.com/t/polls-tutorial-not-found-error/4175/18 "2020-09-04T15:34:50Z")

</div>

So I’ve gone through the whole tutorial again and corrected various typos. It now works.

> Using `/polls/1/vote` isn’t going to work because you didn’t supply the trailing `/` .

This was especially helpful, I made that mistake or similar a couple of times.

Thanks for all your help.
