3

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>

2 Answers 2

3

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 %}>
Sign up to request clarification or add additional context in comments.

2 Comments

still not clear. in my example {{gamestoday|lookup:i}} gamestoday is just a list passed from the homeView with lookup being a custom tag used for getting the value on position i from the list. since all the data comes from an api, I am not planning on storing it in my own db.
you can than use the django default tag {% with param=gamestoday|lookup:i %} and pass param into the url. Remember to close with {% endwith %}.
0

Found quite an easy solve, syntax-related:

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.