'How to get a url param in a django template?

I need to get the param of the url inside a html file, but I need to know if is possible in a tag, or how can I get the url params using Class-based views?


My urls.py file

from django.urls import path
from .views import UsersView


urlpatterns = [
    path('list/<int:pk>/', UsersView.as_view(), name='user_list'),
]

My html file:

<!DOCTYPE html>


<html lang="en">

<head>
    <title>Users</title>
</head>


<body>
    {{ request.GET.pk }}
</body>


</html>


Solution 1:[1]

You can use

self.kwargs['pk']

Inside a CBV to get the URL parameter, since there is a <int:pk>

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 crimsonpython24