Can't get single checkbox to render in Flask WTF -
i've been searching long time examples on how use checkboxes flask wtf, seems either there no example or there complex ones involve list of checkboxes.
i did find 1 example in miguel's blog here, i'm not able checkbox render. here's did:
first off, form class:
class loginform(form): email = textfield("email address", validators=[validators.required()]) password = passwordfield("password", validators=[validators.required()]) remember_me = booleanfield("remember me", default = false) submit = submitfield("login")
and in template:
<form class="form-signin" role="form" action="{{ url_for('login') }}" method="post"> {{ form.hidden_tag() }} <div class="form-group"> {{ form.email.label }} {{ form.email ( ** {'class' : 'form-control'} ) }} </div> <div class="form-group"> {{ form.password.label }} {{ form.password ( ** {'class' : 'form-control'} ) }} </div> <div class="form-group"> {{ form.remember_me }} remember me </div> </form>
in final output of form, checkbox missing:
if see generated html, field missing:
<form class="form-signin" role="form" action="/login" method="post"> <div style="display:none;"><input id="csrf_token" name="csrf_token" type="hidden" value="1457326344##3036eeab4ffa39494ee92247925a30a88a69432f"><input id="next" name="next" type="hidden" value=""></div> <div class="form-group"> <label for="email">email address</label> <input class="form-control" id="email" name="email" type="text" value=""> </div> <div class="form-group"> <label for="password">password</label> <input class="form-control" id="password" name="password" type="password" value=""> </div> <div class="form-group"> remember me </div> <div class="form-group"> <input class="btn btn-primary btn-lg" id="submit" name="submit" type="submit" value="login"> </div> </form>
curiously, if try add {{ form.remember_me.label }}
template, exception jinja2.exceptions.undefinederror: 'flask_security.forms.loginform object' has no attribute 'remember_me'
.
i came across solutions mention custom widgets, i'm hoping hear won't have go route simple, single checkbox.
what doing wrong? if nothing, what's shortest, painless way accomplish this?
~~~~update~~~~
it looks there's weird behavior @ work here. field form.remember
seems produce checkbox, , form.remember.label
produces default "remember me" label. using other name causes aforesaid exception occur.
i found mistake. import from security import *
caused flask-security template loginform
creep namespace, causing weird behavior. needed make changes forms, importing form
flask.ext.wtf
rest of fields wtforms
. hope helps somebody!
Comments
Post a Comment