Hey there! This problem might be a bit unpredictable, but give it a go and let us know how you do!
Given an SQLite database 'users' with columns 'username' and 'email', consider the Flask application below. What is the correct way to use raw SQL to insert data into the 'users' table?
from flask import Flask, g
import sqlite3
def get_db():
db = getattr(g, '_database', None)
if db is None:
db = g._database = sqlite3.connect(DATABASE)
return db
@app.teardown_appcontext
def close_connection(exception):
db = getattr(g, '_database', None)
if db is not None:
db.close()