[Django]-Django crispy-forms – Custom button

3👍

I figured it out, I used the following;

self.helper.add_input(Button('cancel', "Cancel", css_class='btn', onclick="javascript:location.href = '/customeroverview';"))
👤phicon

2👍

This page has another way:

HTML("""<a role="button" class="btn btn-default"
    href="{% url "some_cancel_url" %}">Cancel</a>"""),

So some_cancel_url is the name of the url you want to go to.

Seems a little hackish, but I think an anchor is better than javascript. Better for search engines, people without JS or simply for checking out the link by hovering.

👤Mark

Leave a comment