article

Saturday, October 17, 2020

How to create Flask SQLite Database

 



How to create Flask SQLite Database
Python has built-in support for SQLite. The SQlite3 module comes with the Python release.
In this article you will learn how the Flask application interacts with SQLite.
#app.py
from flask import Flask
import sqlite3

app = Flask(__name__)

conn = sqlite3.connect('database.db')
print("Opened database successfully");

conn.execute('CREATE TABLE students (name TEXT, addr TEXT, city TEXT, pin TEXT)')
print ("Table created successfully");
conn.close()

if __name__ == '__main__':
   app.run(debug = True)

Related Post