Flask-Workshop/09-sessions.py

16 lines
493 B
Python
Raw Normal View History

2020-11-22 13:41:09 +00:00
from flask import Flask, render_template, request, make_response
app = Flask(__name__)
@app.route('/', methods=['POST', 'GET'])
def index():
if request.method == 'GET':
name = request.cookies.get('name')
return render_template('cookies.html', name=name)
else:
name = request.form['name']
resp = make_response(render_template('cookies.html', name=name))
resp.set_cookie('name', name)
return resp
if __name__ == '__main__':
app.run()