PDA

Archiv verlassen und diese Seite im Standarddesign anzeigen : flask - POST Problem


Lord_X
2014-07-09, 08:46:31
Hallo zusammen :)

Ich komme hier im Moment nicht weiter oder stehe auf dem Schlauch! Jemand eine Idee, wo mein Fehler ist?


1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 from flask import Flask, request, render_template
5
6 app = Flask(__name__)
7
8 app.config.update(
9 DEBUG=True
10 )
11
12 @app.route("/")
13 def test():
14 option_list = {'wert_1': '1', 'wert_2':'2'}
15 return render_template("test.html", option_list=option_list)
16
17
18 @app.route("/", methods=['POST'])
19 def test_post():
20 opt = request.form['test1']
21 print opt
22
23 if __name__ == "__main__":
24 app.run(host='0.0.0.0', port=8080)



1 <!DOCTYPE html>
2 <html lang="en">
3 <body>
4
5 <form name="test1" action="{{ url_for('test_post') }}" method="POST">
6
7 <select name="option">
8 {% block content %}
9 {% for o in option_list %}
10 <option name="{{ o }}" SELECTED>{{ o }}</option>
11 {% endfor %}
12 {% endblock %}
13 </select>
14
15
16 <button type="submit">OK</button">
17
18 </form>
19
20 </body>
21 </html>


Danke

Lord_X
2014-07-09, 09:56:06
Ahhhh gefunden! Das "name" Attribut muss auf dem "select element" sein.


18 @app.route("/", methods=['POST'])
19 def test_post():
20 opt = request.form['option']
21 print opt
22 return opt