Introduction
Flask is a lightweight and easy-to-use web framework for Python. It's great for beginners who want to build a simple server. In this guide, we'll walk you through the steps to create a basic Flask server.
STEP-1
Install flask
pip install flask
STEP-2
Create a new folder for your project. You can name it anything you like, for example, flask-server.
STEP-3
Inside your project folder, create a new file named app.py. This is where we will write our server code.
STEP-4
Write Your Flask Server Code
Open app.py in a code editor and write the following code:
from flask import Flask app = Flask(__name__) @app.route('/') def home(): return "Hello, World!" if __name__ == '__main__': app.run(debug=True)
STEP-5
Run your flask server
python app.py
The above is the detailed content of Build a server with python flask. For more information, please follow other related articles on the PHP Chinese website!