[英]Django crispy-forms - Custom button
I have two buttons in my django-crispy-form 我的django-crispy-form中有两个按钮
self.helper.add_input(Submit('submit', 'Submit'))
self.helper.add_input(Button('cancel', 'Cancel'))
The submit button works just fine, the cancel button does nothing. 提交按钮工作正常,取消按钮什么都不做。 As i am quite new to django/pyhton, how would i add a goto url (eg url below) to the action of the cancel button? 由于我是django / pyhton的新手,我如何在取消按钮的操作中添加goto url(例如下面的url)?
url(r'^customeroverview/$', 'customer.views.customeroverview', name='customeroverview'),
I have read that this is possible with JQuery, but this is something i never used. 我已经读过这可以用JQuery,但这是我从未使用过的东西。 Eager to learn so if this would be the best option i am open to suggestions. 渴望学习,如果这是最好的选择,我愿意接受建议。 Keep in mind i use the crispy form and want to use ass little html as possible. 请记住,我使用脆皮形式,并希望尽可能使用ass html。
If jQuery is used; 如果使用jQuery;
我想通了,我使用了以下内容;
self.helper.add_input(Button('cancel', "Cancel", css_class='btn', onclick="javascript:location.href = '/customeroverview';"))
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. 所以some_cancel_url
是你要去的网址的名称 。
Seems a little hackish, but I think an anchor is better than javascript. 似乎有点hackish,但我认为锚比javascript更好。 Better for search engines, people without JS or simply for checking out the link by hovering. 更适合搜索引擎,没有JS的人或只是通过悬停检查链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.