I had a similar problem, so, you can do this to use wtforms, and simply call {{ render_temple(form) }}
in html to get this result.
class InlineButtonWidget(object):
def __init__(self, class_=None):
self.class_ = class_
def __call__(self, field, **kwargs):
kwargs.setdefault('type', 'submit')
kwargs["class"] = self.class_
title = kwargs.pop('title', field.description or '')
params = html_params(title=title, **kwargs)
html = '<button %s>%s</button>'
return HTMLString(html % (params, escape(field.label.text)))
class InlineButton(Field):
widget = InlineButtonWidget()
def __init__(self, label=None, validators=None, text='Save', **kwargs):
super(InlineButton, self).__init__(label, validators, **kwargs)
self.text = text
def _value(self):
if self.data:
return u''.join(self.data)
else:
return u''
Usage:
class BookForm(FlaskForm):
text = Markup('<i class="fas fa-sign-in-alt"></i> Submit')
submit = SubmitField(text, widget=InlineButtonWidget(class_="btn btn-info")) #This class_ param it's applied in the class of the button in HTML.
Output:
Html code
Display
My reply is based on this post WTForms creating a custom widget.