Making a submit button form field

﹥>﹥吖頭↗ 提交于 2019-12-23 17:29:08

问题


So there exists a snippet here:

I was going tor reuse this, but when I declare this in my forms.py, and I render the html..

submit_button = SubmitButtonField()

value is not supplied (it's escaped to string None), while name is default to submit_button, probably because of the forms.Widget constructor.

How can I supply the name and the value? I tried to write an init method for the widget...

def __init__(self, name, value, label, attrs):        
    print '%s, %s, %s, %s' %(name, value, label, attrs)
    self.name, self.value,self.label = name, value, label
    self.attrs = attrs

But this doesn't quite make sense if the field is always (supposedly) default to use the widget SubmitButtonWidget... instead I should supply these values in the field init method. But it doesn't allow me to do.

How should I rewrite this snippet so it can accept my supplied values?


回答1:


As written in the comment at the very top of the snippet, the usage is

submit_button = SubmitButtonField(label="", initial=u"Your submit button text")

Your missing value comes from the initial keyword argument. The name is the name of the form field.



来源:https://stackoverflow.com/questions/10868873/making-a-submit-button-form-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!