from flask import Flask app = Flask(__name__) # at this point, app is ready to respond to all requests with a 404 error # we will register paths with other responses below. # run it either with the command line invocation # python3 -m flask --app flask-demo.py run # or by adding code to this file as follows: # if __name__ == '__main__': # app.run() # register a path for the default method (GET) @app.route("/") def any_name_you_want(): return "
Hi from 340!
" # register a path for the GET method # note: the paths are exact; /code/ and /CODE do not match this @app.get("/code") def a_different_name(): return "You asked for /code
" # register a path for the POST method @app.post("/code") def a_third_name(): return "Thanks for sending us your code
" # register a path with wildcards; argument must match angle-bracketed part of path @app.get("/welcome/Hello, "+user+", thanks for telling us "+repr(greeting)+"!
" # register several methods to the same function with a request body @app.route("/echo", methods=["GET","POST"]) def echo(): from flask import request return f'''You used method {request.method}
You send the following form data: {request.form}
'''