How to Set Up Flask with Python?

Estimated read time 1 min read

To set up Flask with Python, you can follow these steps:

  1. Install Python on your computer, if you haven’t already. You can download the latest version of Python from the official Python website.
  2. Install Flask by running the following command in your terminal:
pip install Flask
  1. Create a new Python file in your preferred code editor, and add the following code:
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
    return 'Hello, World!'
  1. Save the file with a .py extension.
  2. In your terminal, navigate to the directory where your file is located.
  3. Run the following command to start the Flask development server:
export FLASK_APP=<filename>.py
flask run

Replace <filename> with the name of your Python file.

  1. Open your web browser and go to http://localhost:5000/. You should see a “Hello, World!” message displayed in your browser.

That’s it! You have successfully set up Flask with Python. From here, you can start building your Flask application by adding more routes and functionality.

You May Also Like

More From Author

+ There are no comments

Add yours

Leave a Reply