get request, post request, forms,
+33 −1 · 2 files changed
-
flask-blog.py+10 −1 -
templates/form.html+23 −0
@@ -1,4 +1,4 @@ -from flask import Flask, render_template +from flask import Flask, render_template,request from flask.ext.bootstrap import Bootstrap @@ -39,6 +39,15 @@ def index(): return render_template('weather-average.html', city='Portland, OR', months=months, weather=weather, highlight=highlight) + +@app.route('/jin2/form', methods=['GET','POST']) +def findex(): + name = None + if request.method == 'POST' and 'name' in request.form: + name = request.form['name'] + return render_template('form.html', name=name) + + @app.errorhandler(404) def not_found(e): return render_template('404.html') @@ -0,0 +1,23 @@ +{% extends "bootstrap/base.html" %} + +{% block title %}Form Example{% endblock %} + +{% block navbar %} + <nav class="navbar navbar-inverse" role="navigation"> + <div class="container"> + <a class="navbar-brand" href="{{ url_for('index') }}">Hello</a> + </div> + </nav> +{% endblock %} + +{% block content %} + <div class="container"> + <form method="POST" action=""> + What is your name? <input type="text" name="name"> + <input type="submit" name="submit" value="Submit"> + </form> + {% if name %} + <h1>Hello, {{ name }}!</h1> + {% endif %} + </div> +{% endblock %} \ No newline at end of file