Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Reference Django URL in HTML Button

I have the following url in my urls.py

url(r'^inline-formset/$', 'order.views.addrow', {'form_class': OrderedItemForm}, name='addrow'),

Now i would like to reference this url from a form button but i am not getting the syntax right.

This works:

<a href="{% url 'addrow' %}">New Line</a>

This has the wrong syntax, please assist

<input class="btn btn-success" type="button" value="New Line" onclick="location.href="{% url 'addrow' %}""  />
like image 906
phicon Avatar asked Oct 16 '14 11:10

phicon


2 Answers

Your specific problem is that you have a conflict with quote types. Use this instead:

onclick="location.href='{% url 'customeroverview' %}'"

but note that this is not really a good way of doing things. If you just want a link that looks like a button, then have a normal a href and use CSS to style it like a button. In Bootstrap, for example, you can use the "btn btn-*" classes on any element to make it look like a button.

like image 135
Daniel Roseman Avatar answered Nov 18 '22 20:11

Daniel Roseman


Make sure you have a url specified in urls.py for "customeroverview"

something like

url(r'^xxx/$', 'xxx.views.function', name='customeroverview')

like image 29
Mithu Avatar answered Nov 18 '22 20:11

Mithu