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

Flask SQLAlchemy

Before we can abstract our data, we need to set up Flask SQLAlchemy. SQLAlchemy creates its database connection through a special database URI. This is a string that looks like a URL that contains all the information that SQLAlchemy needs to connect. It takes the general form of the following code:

databasetype+driver://user:password@host:port/db_name 

For each driver that you installed previously, the URI would be as follows:

# SQLite connection string/uri is a path to the database file - relative or absolute.
sqlite:///database.db 
# MySQL 
mysql+pymysql://user:password@ip:port/db_name 
# Postgres 
postgresql+psycopg2://user:password@ip:port/db_name 
# MSSQL 
mssql+pyodbc://user:password@dsn_name 
# Oracle 
oracle+cx_oracle://user:password@ip:port/db_name ...
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