Notes Single

Flask is a lightweight, modular, Python framework for web development. For install Flask:

pip install flask

First App

Creation of the app and static routes

You must create a directory called "app" in the root of the project and inside create a file "" with the following content. This will be the main file of the application.

from flask import Flask  # Importing Flask
app = Flask(__name__)  # Create an instance of Flask and define '' like the root

# For every route must exist a function
@app.route('/')  # Route for domain root
def hello_world():  #Function which define the actions to do when the route receive a HTTP request
    return 'Hello world!'  # Statement retrieved by the function

@app.route('/other-url')  # Route for 'domain/other-url'
def other_function():
    return 'Hello world in other URL!'  # Statement retrieved by the function

Run a server

if __name__ == '__main__':, port=80)

Finally, we execute the file '' in the terminal

Python ./app/

Thanks for reading :)
I invite you to continue reading other entries and visiting us again soon.

Related Posts: