Created
March 24, 2022 05:56
-
-
Save natanfeitosa/f3551e3113627076f16b1ac76e98136a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from flask import Flask, request, make_response | |
app = Flask(__name__) | |
@app.route('/') | |
def visit_counter(): | |
visits = int(getattr(request.cookies, 'visits', 0)) + 1 | |
msg = f''' | |
<h1> | |
{visits} visita{"s" if visits > 2 else ""} | |
</h1> | |
''' | |
res = make_response(msg) | |
res.set_cookie('visits', str(visits)) | |
return res | |
@app.route('/reset') | |
def reset_counter(): | |
res = make_response('Resetting... ok') | |
res.set_cookie('visits', '0', 0) | |
return res | |
if __name__ == "__main__": | |
app.run(host='0.0.0.0', port=4000) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment