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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With