[英]Django template and dynamic url
I have a few links that I need to link to via a submit button. 我需要通过“提交”按钮链接到一些链接。 Let's say that I have links_
假设我有links_
http://link/problem1
http://link/problem2
http://link/problem3
In my django template I'm trying to link to a random link out of those three: So in my django template I have: 在我的django模板中,我尝试链接到这三个中的随机链接:所以在我的django模板中,我有:
<a href="http://link/problem" class="btn btn-success"> Some Text </a>
Is there a way that I can have a numeric loop that would loop through numbers 1 to 3 and add those numbers to the 有没有一种方法可以使数字循环遍历数字1到3,并将这些数字加到
http://link/problem
I have found a few examaples on how to make a numeric for loop in a django template but I dont know how to add those numbers to the link in an a tag. 我已经找到了一些关于如何在Django模板中制作数字for循环的范例,但我不知道如何将这些数字添加到标签中的链接中。
Use center
default filter to create a string of 3 spaces, then loop over it and use forloop.counter
in template 使用
center
默认过滤器创建一个由3个空格组成的字符串,然后对其进行循环并在模板中使用forloop.counter
{% with ''|center:3 as range %}
{% for _ in range %}
<a href="http://link/problem{{forloop.counter}}" class="btn btn-success"> Some Text </a>
{% endfor %}
{% endwith %}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.