- Create a basic Flask application
-
Create a Flask Application
- Name it FlaskApp_01
-
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()-
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
-
View your Application
- Open your browser and type in the URL http://localhost:5000 and hit enter. You should see this
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).
