Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

django

jinja2

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

like image 549
Jack Avatar asked Sep 07 '25 14:09

Jack


1 Answers

I found a solution:

{% for User in all_users %}
    {{ url('detail', args=[User.id] )}}
{% endfor %}
like image 193
Jack Avatar answered Sep 11 '25 10:09

Jack