Skip to content

Latest commit

 

History

History
44 lines (29 loc) · 1.33 KB

File metadata and controls

44 lines (29 loc) · 1.33 KB

Lesson 1 - Introduction to Flask - Hello World with variable

Learning Objectives

  • Create a basic Flask application

The Walkthrough

  1. Create a Flask Application

    • Name it FlaskApp_01
  2. Edit the main python file (FlaskApp_01.py)

    • Make it look like the following
from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello_world():
    return "Hello World!"

if __name__ == '__main__':
    app.run()
  1. Run your application

    • To run the application click the run button in the upper right hand corner:
    • Alternatively, you can run the application from the terminal using the command: python ./FlaskApp_01.py
  2. View your Application

Running your first Flask Application

What is Going On

In Line 1 of FlaskApp_01.py, we are importing the Flask class into our project to make the @app.route decorator work.

In Line 2, we create a new instance of the flask class.

@app.route indicates what path or endpoint the user will visit. The function following this annotation (in this case, the hello_world function) is run each time that the path is accessed. Here, the default path is the only path that is specified out.

We use app.run() to run our app on a local server (default port 5000).