We can kick-start our application development with a simple example, which gives you an idea of how we program in Python with a flask framework. In order to write this program, we need to perform the following steps:
route
method which associates a URL and the function which handles it.Here is an example which follows the preceding steps to make a simple application:
from flask import Flask app = Flask(__name__) @app.route("/") def home(): return "Hello Guest!" if __name__ == "__main__": app.run()
In the preceding lines of code, we have created a WSGI application instance using the Flask's Flask
class, and then we defined a route which maps the path "/
" and the view function home
to process the request using a Flask's decorator function Flask.route()
. Next, we used the app.run()
which tells the server to run the code. And at that end, it will result in a web page showing up "Hello Guest!",
when the code is executed.
3.145.78.136