Search code examples
djangojinja2

Django & Jinja2 templates using {{ url() }}


I am trying to figure out how to pass my user_id within my html using jinja's {{ url() }}, using urls that don't need any id like /dashboard/ work fine but I need to pass an id to this- example: /user/3 . I have tried the following with no success:

{{ url('detail') }}
{{ url('detail', user_id=User.id) }}
{{ url('detail', User.id) }}

Here's part of my views and html:

views.py

urlpatterns = [
    path('dashboard/', dashboard, name='dashboard'),          
    path('user/<int:user_id>/', detail, name='detail'),    
]

dashboard.html

{% for User in all_users %}

    {{ url('detail') }}

{% endfor %}

Any help on this would be appreciated, thanks


Solution

  • I found a solution:

    {% for User in all_users %}
        {{ url('detail', args=[User.id] )}}
    {% endfor %}