# Django Tutorial Part 2 Adding views to url path

**URL:** <https://forum.djangoproject.com/t/django-tutorial-part-2-adding-views-to-url-path/21921>\
**Category:** Getting Started\
**Created:** [June 28, 2023, 4:42am UTC](https://forum.djangoproject.com/t/django-tutorial-part-2-adding-views-to-url-path/21921 "2023-06-28T04:42:52Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![strikeouts27](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/strikeouts27/32/13899_2.png) [@strikeouts27](https://forum.djangoproject.com/u/strikeouts27)\
**Post date:** [June 28, 2023, 4:42am UTC](https://forum.djangoproject.com/t/django-tutorial-part-2-adding-views-to-url-path/21921/1 "2023-06-28T04:42:53Z")

</div>

> **[Django](https://docs.djangoproject.com/en/4.2/intro/tutorial03/)**
>
> The web framework for perfectionists with deadlines.

Hello Django Forums,

In order to get better at Django I am going through the Django tutorial polls app so that I can better understand the fundamentals. I have a question about the following code presented in the tutorial.

```auto
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"),
]

```

When somebody requests a page from your website – say, “/polls/34/”, Django will load the `mysite.urls` Python module because it’s pointed to by the [`ROOT_URLCONF`](https://docs.djangoproject.com/en/4.2/ref/settings/#std-setting-ROOT_URLCONF) setting. It finds the variable named `urlpatterns` and traverses the patterns in order. After finding the match at `'polls/'` , it strips off the matching text (`"polls/"` ) and sends the remaining text – `"34/"` – to the ‘polls.urls’ URLconf for further processing. There it matches `'<int:question_id>/'` , resulting in a call to the `detail()` view like so:

detail(request=, question\_id=34)

The `question_id=34` part comes from `<int:question_id>`. Using angle brackets “captures” part of the URL and sends it as a keyword argument to the view function. The `question_id` part of the string defines the name that will be used to identify the matched pattern, and the `int` part is a converter that determines what patterns should match this part of the URL path. The colon (`:`) separates the converter and pattern name.

I want to walk through what is going on during this explanation and see if I understand this correctly.

Basically /polls/34/ is requested from the user. Django will go to the projects urls because in settings.py we told django to look in that location.

It finds the variable named urlpatterns and goes through each path one by one. It finds the ‘polls/’ path and than strips off the ‘polls/’ portion of /polls/34 and leaves the 34/ left. It sends that to the urls.py for the app which in this case would be polls.urls. for further processing.

Which is shown in this code snippit below.

```auto
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"),
]

```

First Question:  
Once there, and this is where I get hazy, it goes down the urls path’s and finds int:question\_id/ and runs the detail view. Is this because this is the first thing it runs into that has the int:question\_id? I observe that it is at the top of the list.

Second Question  
The rest of the request that was not stripped off the 34/ seems to have activated the detail view. And I am thinking that it assigns question\_id a value of the number that the user requested in their url 34.

I think I am off on a detail. Where am I off?

---

<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:** [June 28, 2023, 12:14pm UTC](https://forum.djangoproject.com/t/django-tutorial-part-2-adding-views-to-url-path/21921/2 "2023-06-28T12:14:09Z")

</div>

> [@strikeouts27](#):
>
> I think I am off on a detail. Where am I off?

This process is described in detail at [URL dispatcher | Django documentation | Django](https://docs.djangoproject.com/en/4.2/topics/http/urls/#how-django-processes-a-request).
