Notes from Flask Mega Tutorial Miguel Gringberg # Lesson 1 Lesson one sets up python, virutal environment etc. Then it sets up the basic framework of a flask app ``` >app |-- __init__.py <- import Flask and initiate |-- routes.py <-- this routes different url in the applicaiton microbolog.py ``` The routes file is imported into the namespace in the __init__.py file however it is imported at the end of the file. This is done to workaround *circular imports* a common problem with Flask applications because routes needs to import app in return. ### Routing Routing in Flask is handled by different functions called *view* functions The view functions are decorated with `@app.route('/')` etc.. decorators. To start the app type: ```python export FLASK_APP=microblog.py flask run ``` # Lesson 2 Jinja templates enable you to structure a HTML file with holes that can be filled with variables. You can do stuff like conditional logic and for loops. You can inherit a template into another template and fill a block inside it. The `render_template` function in flask looks for a "templates" folder and gets the template files from there specified. You can pass the variables as keyword arguments. Check example for more details. # Lesson 3 Every application needs configs. You can store and retrieve your configs inside `app.config` variable like a dictionary. For *separation of concerns* keep the config settings separately in `config.py` file. Make sure you keep any secrets in the `.env` file that is not in source control. `app.config.from_object(Config)` enables you to load the configs from a class Config