flask minimul app
Import the Flask module: The first step is to import the Flask module, which provides the functionality to create a web application using Flask.
Create an instance of the Flask class: Next, you need to create an instance of the Flask class, which represents the web application. This instance will be used to configure and run the application.
Define a route and a view function: A route is a URL that the application will respond to. You can define routes using the
@app.route
decorator. Inside the view function, you can define the logic for what should happen when that route is accessed.Run the application: Finally, you need to run the application by calling the
run()
method on the Flask instance. This will start a development server and make the application accessible on a specified host and port.
Here's an example of a minimal Flask app that follows these steps:
from flask import Flask
app = Flask(__name__)
@app.route('/')
def hello():
return 'Hello, World!'
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5000)
Note: The code above assumes that you have already installed Flask. If not, you can install it using pip install flask
.