July 2019
Beginner to intermediate
302 pages
9h 38m
English
Let's create a small application in this recipe to understand the basic database connection with Flask. We will build over this application in the next few recipes. Here, we will just see how to create a db instance and some basic database commands. The file's structure would look like the following:
flask_catalog/
- run.py my_app/ - __init__.py
First, we start with flask_app/run.py. This is the usual run file that we have read about previously in this book:
from my_app import app app.run(debug=True)
Then, we configure our application configuration file, that is, flask_app/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' ...