October 2018
Intermediate to advanced
332 pages
8h 9m
English
At first, it looks like a lot has changed but you will see that, taking into account the previously explained structure, the changes are simple and natural.
First, we have moved our SQLAlchemy code to the models.py file inside the blog module folder. We just want to move the model definitions, not any database initialization code. All initialization code will be kept in the main application module, webapp, inside __init__.py. The import section and database-related object creation appear as follows:
from flask import Flask, render_templatefrom flask_sqlalchemy import SQLAlchemyfrom flask_migrate import Migratedb = SQLAlchemy()migrate = Migrate()def page_not_found(error): return render_template('404.html'), 404def create_app(config): ...