Flask-Workshop/08-request-handling.py

19 lines
522 B
Python

from flask import Flask, render_template, request, redirect, url_for
app = Flask(__name__)
counter = 0
@app.route('/', methods=('GET', 'POST'))
def index():
global counter
if request.method == 'GET':
return render_template('request-handling.html', counter=counter)
else:
if request.form.get('btn') == 'down':
counter -= 1
elif request.form.get('btn') == 'up':
counter += 1
return redirect(url_for('index'))
if __name__ == '__main__':
app.run()