3 ms·
I don't have something clean, but I pushed a demo https://github.com/rahulkmr/flask-bigapp-template https://github.com/rahulkmr/flask-bigapp-template The focus
by irahul 14y ago
I don't have something clean, but I pushed a demo https://github.com/rahulkmr/flask-bigapp-template https://github.com/rahulkmr/flask-bigapp-template
The focus points are:
1. Routes in a separate file. Check config/urls.py
2. Blueprints are level of abstraction. Check blueprints/post. It's a simple blogging app. Blueprints have their own forms, models, urls, views.
3. Add blueprints to the app under config/blueprints.py You can mount the blueprint at '/' or an url prefix viz '/posts'
4. Blueprints define their own hooks. Check blueprints/post/__init__.py for an example.
5. Schema migration using alembic. Write your model:
class Post(db.Model):
id = db.Column(db.Integer, primary_key=True)
name = db.Column(db.String(80))
title = db.Column(db.String(200))
content = db.Column(db.Text)
def __init__(self, name, title, content):
self.name = name
self.title = title
self.content = content
Save your file and add the blueprint to config/blueprints.py(if it's a blueprint), and run:
alembic revision --autogenerate -m "Create post table."
Check the generated schema in migrate/versions/ Tweak the migration and then `alembic upgrade head`
6. Flask-WTF and wtforms in general used for validation.
7. settings.py used for hooks. See config/settings.py and main.py
main.py is the glue. The code is quite simple as it doesn't do much. Ignore manage.py. That's my personal scaffold generator(like rails). Also ignore the custom template formats. That again is my personal slimish jinja templates.
I use some variation of this template in my projects. This is just guidelines. You can modify it to your heart's content to suit your needs.