3 ms·
On the routes side it also means you don't fact around having to import a module to get your app - if you can instantiate the app (as it were) and then set up r
by lifeisstillgood 14y ago
On the routes side it also means you don't fact around having to import a module to get your app - if you can instantiate the app (as it were) and then set up routes you can create a factory much more easily and pass it around with little worries - but anchored to a module import as in the docs is less than helpful
Would love to see or hear more about your default setups though. Is there an example in OSS?
- ceol 14y agoThat's a great point. I think I will start using that method for defining routes, myself.
- irahul 14y agoI 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.