python - Wtform submission using GET not POST -
i trying simple form work using wtforms, flask, , bootstrap, form submission results in form params instead of post.
i got work flask, when switched importing form flask.ext.wtf, using form.validate_on_submit instead of validate, , using flask_bootstrap, submitting form results in action instead of post action. missing?
here's seeing in console:
get 127.0.0.1 - - [14/apr/2014 21:04:10] "get / http/1.1" 200 - 127.0.0.1 - - [14/apr/2014 21:04:13] "get /?csrf_token=none&recipe1=dfsaasdf&recipe2=adfsadfs&submit_button=submit+form http/1.1" 200 here's app in entirety:
from flask import render_template, request, redirect, url_for flask.ext.wtf import form wtforms.ext.csrf import secureform wtforms import textfield, hiddenfield, validationerror, radiofield,\ booleanfield, submitfield, integerfield, formfield, validators concat.recipe_concatenator import recipeconcatenator flask_bootstrap import bootstrap flask import flask hashlib import md5 app = flask(__name__) bootstrap(app) app.config['debug'] = true secret_key = '1234567890' class recipecompareform (form): recipe1 = textfield('recipe 1', []) recipe2 = textfield('recipe 2') submit_button = submitfield('submit form') @app.route('/', methods=['get', 'post']) def compare(): print request.method form = recipecompareform(csrf_enabled=false) if form.validate_on_submit(): print "validated" print form.recipe1.data message = "blah" return redirect(url_for('results', message=message)) return render_template('form.html', form=form) @app.route('/results') def results(): message = request.args['message'] return render_template('results.html', message=message) if __name__ == '__main__': app.run() the template:
{% extends "bootstrap/base.html" %} {% import "bootstrap/wtf.html" wtf %} {% import "bootstrap/fixes.html" fixes %} {% block content %} <form class="form form-horizontal" role ="form"> {{ form.hidden_tag() }} {{ wtf.form_errors(form, hiddens="only") }} {{ wtf.form_field(form.recipe1) }} {{ wtf.form_field(form.recipe2) }} {{ wtf.form_field(form.submit_button) }} </form> {% endblock %}
if don't specify method attribute, forms default get. use post, add method attribute form tag, this:
<form class="form form-horizontal" role="form" method="post">
Comments
Post a Comment