# Django Url Paramater Integers?

**URL:** <https://forum.codewithmosh.com/t/django-url-paramater-integers/18509>\
**Category:** Python\
**Created:** [March 3, 2023, 2:27am UTC](https://forum.codewithmosh.com/t/django-url-paramater-integers/18509 "2023-03-03T02:27:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Slash](https://avatars.discourse-cdn.com/v4/letter/s/a3d4f5/32.png) [@Slash](https://forum.codewithmosh.com/u/Slash)\
**Post date:** [March 3, 2023, 2:27am UTC](https://forum.codewithmosh.com/t/django-url-paramater-integers/18509/1 "2023-03-03T02:27:13Z")

</div>

In the “Building Web Applications using Django” section of this course.(URL Parameters) Mosh mentions that by default Django uses integers since the movie\_id attribute is an integer. But how come it still displays ‘a’ properly. Shouldn’t an error occur? Thanks!

---

<div class="post-metadata">

**Author:** ![MuhammadNoumanAli](https://avatars.discourse-cdn.com/v4/letter/m/65b543/32.png) [@MuhammadNoumanAli](https://forum.codewithmosh.com/u/MuhammadNoumanAli)\
**Post date:** [June 27, 2023, 2:23pm UTC](https://forum.codewithmosh.com/t/django-url-paramater-integers/18509/2 "2023-06-27T14:23:52Z")

</div>

Yes, Django allows you to define URL parameters that can be integers. URL parameters in Django are placeholders within the URL pattern that capture specific values and pass them as arguments to your views.

To define a URL parameter as an integer, you can use the `<int:parameter_name>` syntax in your URL patterns. Here’s an example:

# urls.py

from django.urls import path  
from . import views

urlpatterns = [  
path(‘example/int:id/’, views.example\_view),  
]

In the above example, the URL pattern `example/<int:id>/` captures an integer value and passes it as an argument named `id` to the `example_view` function in your views module.

You can then access the captured integer value within your view function using the corresponding parameter name. For instance:

# views.py

from django.http import HttpResponse

def example\_view(request, id):  
return HttpResponse(f"The ID is: {id}")

In the `example_view` function, the `id` parameter represents the captured integer value from the URL pattern. You can use it as needed in your view logic.

When a user visits a URL like `/example/42/`, Django will capture the integer `42` and pass it as the `id` argument to the `example_view` function. The function will then return a response that includes the value of `id`.

Note that if the URL parameter is expected to be a non-integer value or if an invalid integer is provided, Django will raise a `404` error by default. You can handle such cases by defining appropriate error handling or validation logic within your views.

Remember to include the appropriate URL pattern and view function in your Django project’s URL configuration to make the integer URL parameter functional.
