python - Flask does not take WTForms input -
i'm tring create app flask wtforms.
in controller.py have:
@mod_private.route('/portfolio/', methods=['get', 'post']) @login_required def portfolio(): print "in portfolio" # read form = createcoinsform(request.form) if request.method == 'post' , form.validate_on_submit(): print form.coins.data #i cannot take value return render_template("private/portfolio.html",form=form) return render_template("private/portfolio.html",form=form)
in forms.py:
class createcoinsform(form): coins = integerfield('coins', [datarequired('num required'), numberrange(min=0, max=10)])
and template
<form method="post" action="/private/portfolio/" accept-charset="utf-8" role="form"> <p> {{ form.coins }}</p> <p><input type=submit value=generate> </form>
my problem, wrote in code cannot retrieve string inserted in template.
your problem suggests using built-in csrf protection on form, , form isn't validating because haven't included csrf token.
try adjusting template so:
<form method="post" action="/private/portfolio/" accept-charset="utf-8" role="form"> {{ form.hidden_tag() }} <p> {{ form.coins }}</p> <p><input type=submit value=generate> </form>
Comments
Post a Comment