Skip to content
pkirlin edited this page Oct 11, 2016 · 18 revisions

Intro to using databases with Flask

Python already includes packages for using pretty much every major DBMS in your Python code. We will illustrate using SQLite to build a simple blogging application.

Set up application folders

Create a new folder for your application. Call it blog. Under that folder, create a subfolder called templates for your templates.

Write SQL code for creating tables.

Typically, Flask apps contain an initialization file called schema.sql that contains SQL commands that create the database tables needed. Inside your blog folder, create a file called schema.sql and put the following in it:

drop table if exists entries;
create table entries (
  id integer primary key not null,
  date text not null,
  title text not null,
  content text not null
);

Use the main wiki page to navigate, not the list of pages directly above, because those are out of order.

Clone this wiki locally