I am using a button on my Django template, After click on the button it should open a link offering by reverse url
( template tags
). I tried with the following code but it didn't work
我在我的Django模板上使用了一个按钮,点击按钮后,它应该通过反向URL(模板标签)打开一个链接。我尝试使用以下代码,但它没有用
<input type= "button" style="float: right;" value="Next Graph" onClick="javascript:location.href = 'reverse(graph_view)';"></input>
I know that some thing is wrong with the above syntax. What will be the right one?
我知道上面的语法有些问题。什么是正确的?
PS: I don't want to use any external library
PS:我不想使用任何外部库
2 个解决方案
#1
1
Just use the actual template tag for this {% url %}
. See: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
只需使用此{%url%}的实际模板标记即可。请参阅:https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
UPDATE
It should look like this:
它应该如下所示:
<input type= "button" style="float: right;" value="Next Graph" onClick="javascript:location.href = '{% url graph_view %}';"></input>
If it still doesn't work, you have some other problem. Create a new question and make sure post any errors and stacktraces you get.
如果它仍然不起作用,你还有其他一些问题。创建一个新问题,并确保发布您获得的任何错误和堆栈跟踪。
#2
0
'reverse' only works server-side, not on templates.
'reverse'仅适用于服务器端,而不适用于模板。
You should use template tags.
您应该使用模板标签。
{% url 'graph_view' %}
See https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url.
#1
1
Just use the actual template tag for this {% url %}
. See: https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
只需使用此{%url%}的实际模板标记即可。请参阅:https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url
UPDATE
It should look like this:
它应该如下所示:
<input type= "button" style="float: right;" value="Next Graph" onClick="javascript:location.href = '{% url graph_view %}';"></input>
If it still doesn't work, you have some other problem. Create a new question and make sure post any errors and stacktraces you get.
如果它仍然不起作用,你还有其他一些问题。创建一个新问题,并确保发布您获得的任何错误和堆栈跟踪。
#2
0
'reverse' only works server-side, not on templates.
'reverse'仅适用于服务器端,而不适用于模板。
You should use template tags.
您应该使用模板标签。
{% url 'graph_view' %}
See https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url.