1

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

<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

2 Answers 2

1

Just use the actual template tag for this {% url %}. See: 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.

Sign up to request clarification or add additional context in comments.

4 Comments

What will be the exact syntax because i have tried with it *** <input type= "button" style="float: right;" value="Next Graph" onClick="javascript:location.href = "{% url host_list %}";"></input> *** but it didn't work
Did you use it with or without the single quotes, i.e. {% url 'host_list' %} or {% url host_list %}? With quotes only works in Django trunk, but can be used now for forward compatibility by adding {% load url from future %} before using the url tag. Otherwise, don't use quotes around the view name.
I used the both i.e. with quotes and without quotes. I think that the problem comes because of quotes. Would you please paste the correct syntax (full <imput>...)?
My answer below is exactly the same. I guess I'll delete it.
0

'reverse' only works server-side, not on templates.

You should use template tags.

{% url 'graph_view' %}

See https://docs.djangoproject.com/en/dev/ref/templates/builtins/#url.

1 Comment

Thanks for replying @dannyroa, i tried with it <input type= "button" style="float: right;" value="Next Graph" onClick="javascript:location.href = "{% url 'graph_view' %}";"></input> but it didn't work. Is there any syntax error?

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.