phicon
phicon

Reputation: 3617

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' %}""  />

Upvotes: 7

Views: 29003

Answers (2)

Daniel Roseman
Daniel Roseman

Reputation: 599450

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.

Upvotes: 32

Mithu
Mithu

Reputation: 101

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

something like

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

Upvotes: 1

Related Questions