Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.13 KB

03_my_first_flask_app.md

File metadata and controls

53 lines (35 loc) · 1.13 KB

Goals

  • Create and run your first Flask app
  • Set the values of FLASK_APP and FLASK_DEBUG environment variables

Getting Started

A minimal Flask application can easily be created in 3 steps and as little as 5 lines of code.

  1. Create a file named app.py inside your portfolio project folder:
from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return 'Hello, World!'
  1. In your terminal or console, navigate to the location of your project folder and set the FLASK_APP environment variable:
Mac:
export FLASK_APP=app.py

Windows:
set FLASK_APP=app.py
  1. Finally, run your application:
flask run

Congratulations! You can now access your app through the url route generated in your terminal or console using your favorite browser.

To quit, press CTRL+C.

To deactivate your virtual environment, enter deactivate.

Bonus: FLASK_DEBUG environment variable

To run your app in debug mode, set the FLASK_DEBUG environment variable to 1 before running the application:

Mac:
export FLASK_DEBUG=1

Windows:
set FLASK_DEBUG=1