in Uncategorized

Flask application structure…

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:

from flaskcasts import app

app.run(debug=app.config['DEBUG'])

When ran, it then goes to the flaskcasts directory since it is a module and runs the code in __init__.py:

from flask import Flask

app = Flask(__name__)

app.config.from_object('config')

from .views.home import home
app.register_blueprint(home)

This will go to the home blueprint and execute that code:

from flask import Blueprint

home = Blueprint('home', __name__)

@home.route('/')
def index():
    return "Welcome to the Index"

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.

Write a Comment

Comment