Flask/Python - handling dropdown to open different HTML pages -
i'm learning flask , python along html , css. i've got flask template render dropdown.
what need this: when select value dropdown opens new html page corresponding value chosen(different page different options chosen).
i tried searching web couldn't resources. when submit dropdown option submit button page gives error message saying:
method not allowed
the method not allowed requested url.
please guide me best possible solution.
below code.
pro.html
<form name="startpage" method="post" action=""> <div class="form-group"> <div class="input-group"> <select name = "method_cipher" id = "method_cipher"> <option value="encrypt">encrypt</option> <option value="decrypt">decrypt</option> </select> <select name = "cipher_type" id = "cipher_type"> <option value="caesar">caesar</option> <option value="transposition">transposition</option> <option value="reverse">reverse</option> </select> </div> <button type="submit" name="submit" value="success" class="btn btn-default">submit</button> </div> </form>
test.py
import flask app = flask.flask(__name__) @app.route('/') def index(): return flask.render_template('pro.html') @app.route("/test" , methods=['get', 'post']) def test(): if flask.request.method == 'post': select = flask.request.form.get('method_cipher') if(select == 'encrypt'): return flask.render_template('lastpage.html') if __name__ == '__main__': app.debug=true app.run()
edit - want open different web pages(html page) different dropdown option chosen user when user chose "encrypt" , submit want open "lastpage.html" if chose "decrypt" other page , on different options. not happening so.
your form in pro.html
sends data url specified action
attribute. if leave out or set empty string did requests goes same page /
.
but set form handling in different view function. want post one.
so change form post correct url
<form ... action="/test" ...>
that work not idea hardcode target url in template. assume using jinja
can let insert url you
<form ... action="{{ url_for("test") }}" ...>
take @ url_for
function if haven't already.
Comments
Post a Comment