Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Django Template: Add Variable Into URL As Parameter

What's the proper way to add {{gamestoday|lookup:i}} into the <a href={%url 'stats'%}>. Do I need to make changes to urls.py?

{% load tags %}
<center>
<div class = "scoreboardbackground">
    <div class="row">
{% for i in ngames %}
    <div class="col">

        
        <a href={%url 'stats'%}>
        <div class="livegamebox">
            {{teamnames|lookup:i|lookup:0}} vs {{teamnames|lookup:i|lookup:1}} - {{gamestoday|lookup:i}}
        
            <br>

            <div style="font-size:12px;">
            {{datetimegames|lookup:i}}
            </div> 
        
            <br>

            <div style = "font-size:30px">
            <b>{{latestscore|lookup:i}}</b>
            </div>
        </div>

        </a>
like image 659
Bogdan Andrei Avatar asked Jun 30 '26 07:06

Bogdan Andrei


1 Answers

You can just pass variables as parameters:

Having:

from django.urls import path
from . import views

urlpatterns = [
    path('user/<str:username>/', views.user_profile, name='user_profile')
]

You can:

 <a href={% url 'user_profile' username=username %}>
like image 143
Alessandro Iaselli Avatar answered Jul 01 '26 23:07

Alessandro Iaselli



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!