'Dynamically setting href attribute using jinja
I have a list of url information which are rendered as table using jinja. I am trying to make the url a hyper link so that if i click on the link it will go it that url page.
Sample url List
myData = [["https://www.w3schools.com/",'tutorial site']]
Jinja Code
<tbody>
{% for value in myData %}
<tr>
<a href="{{ value[0].href }}"><td>
<input class="form-check-input" type="checkbox" value="" id="flexCheckDefault">
{{ value[0] }}
</td></a>
<td>{{ value[1] }}</td>
</tr>
{% endfor %}
</tbody>
I tried in this way but didnt work. How is it possible to set the value of href value dynamically with jinja code. In the above, if i click on https://www.w3schools.com/ url in the table, that page should open in new tab of the browser
Solution 1:[1]
Just use <a href="{{ value }}">. I mean, if you put URLs in myData . Otherwise make MyData contain a list of dictionaries, myData=[{"href": "https://www.w3schools.com/", "title": "tutorial site"} , ] and then you can use <a href="{{ value['href'] }}">.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | jsbueno |
