Skip to Content
Flask Framework Cookbook - Second Edition
book

Flask Framework Cookbook - Second Edition

by Shalabh Aggarwal
July 2019
Beginner to intermediate
302 pages
9h 38m
English
Packt Publishing
Content preview from Flask Framework Cookbook - Second Edition

How to do it...

The new directory layout would appear as follows:

flask_catalog/ 
    - run.py    my_app/ 
        - __init__.py 
        catalog/ 
            - __init__.py 
            - views.py 
            - models.py 

First of all, start with modifying the application configuration file, that is, flask_catalog/my_app/__init__.py:

from flask import Flask 
from flask_sqlalchemy import SQLAlchemy 
 
app = Flask(__name__) 
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:////tmp/test.db' 
db = SQLAlchemy(app) 
 
from my_app.catalog.views import catalog 
app.register_blueprint(catalog) 
 
db.create_all() 

The last statement in the file is db.create_all(), which tells the application to create all the tables in the database specified. So, as soon as the application runs, all the tables will be created if they are not ...

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

Writing a Web Application with Flask

Writing a Web Application with Flask

Doug Farrell
Mastering Flask

Mastering Flask

Jack Stouffer

Publisher Resources

ISBN: 9781789951295Supplemental Content