Skip to Content
Mastering Flask Web Development - Second Edition
book

Mastering Flask Web Development - Second Edition

by Daniel Gaspar, Jack Stouffer
October 2018
Intermediate to advanced
332 pages
8h 9m
English
Packt Publishing
Content preview from Mastering Flask Web Development - Second Edition

Refactoring the code

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): ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Start your free trial

You might also like

Flask Web Development, 2nd Edition

Flask Web Development, 2nd Edition

Miguel Grinberg
Flask Web Development

Flask Web Development

Miguel Grinberg

Publisher Resources

ISBN: 9781788995405Supplemental Content