Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make the href for a button use urls.py?

I need to add a 'Cancel' button to my ModelForm, I am using crispy forms but when I add href='personnel-index' to redirect back to the list view, it does not. I've checked their documentation but no luck nor any luck on Google.

like image 576
user1086337 Avatar asked Dec 18 '13 11:12

user1086337


1 Answers

Sometimes the browser's 'Back' button does just as well as a 'Cancel' button in a web form, but if you are absolutely sure you need one, you can always use the HTML object in crispy forms. Something like this would work:

HTML("""<a class="classes-for-styling" href="/personnel/list/">Cancel</a>""")

And, even better, you can include context aware tags to avoid hard-coding urls into your form:

HTML("""<a class="classes-for-styling" href="{% url 'personnel-index' %}">Cancel</a>""")

Then it's just up to you to style your link so it looks like a button.

like image 107
katyjg Avatar answered Sep 30 '22 07:09

katyjg