pythondjangodjango-templatesquerystringparameter

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>

Solution

  • Found quite an easy solve, syntax-related:

    Modified the template's anchor element like this - <a href={%url 'stats' %}?game={{gamestoday|lookup:i}}>