One of the beautiful things about Flask is the freedom to do whatever the hell you want. Unfortunately, for me as a novice, this can be a huge disadvantage at the same time. Not knowing all of the best practices can cause some unnecessary headache. Lucky for me there are a lot of blog entries out there to help get this off the ground.
Blueprints is a flask feature that allows you to organize your app in a modular way. Each “section” will act almost as if it is it’s own application. I took a screenshot of my current directory structure to show you what it looks like. So the project itself would be considered a repository,
and will end up on github at some point as I make more solid plans.
Right now I just wanted to get something running even if it is technically just a simple and basic “Hello World.”
Currently the run.py file contains:
[pastacode lang=”python” manual=”from%20flaskcasts%20import%20app%0A%0Aapp.run(debug%3Dapp.config%5B’DEBUG’%5D)%0A” message=”” highlight=”” provider=”manual”/]
When ran, it then goes to the flaskcasts directory since it is a module and runs the code in __init__.py:
[pastacode lang=”python” manual=”from%20flask%20import%20Flask%0A%0Aapp%20%3D%20Flask(__name__)%0A%0Aapp.config.from_object(‘config’)%0A%0Afrom%20.views.home%20import%20home%0Aapp.register_blueprint(home)” message=”” highlight=”” provider=”manual”/]
This will go to the home blueprint and execute that code:
[pastacode lang=”python” manual=”from%20flask%20import%20Blueprint%0A%0Ahome%20%3D%20Blueprint(‘home’%2C%20__name__)%0A%0A%40home.route(‘%2F’)%0Adef%20index()%3A%0A%20%20%20%20return%20%22Welcome%20to%20the%20Index%22″ message=”” highlight=”” provider=”manual”/]
The only other file is config.py and it basically holds the DEBUG=True boolean only.
Structurally, for a very basic application that is only going to feed videos from a YouTube or similar service, this should suffice.