Python code (app.py):
from flask import Flask, render_template, url_for
from flask_sqlalchemy import SQLAlchemy
from flask_login import UserMixin
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db'
app.config['SECRET_KEY'] = 'thisisasecretkey'
db = SQLAlchemy(app)
class User(db.Model, UserMixin):
id = db.Column(db.Integer, primary_key=True)
username = db.Column(db.String(20), nullable=False)
password = db.Column(db.String(80), nullable=False)
@app.route('/')
def home():
return render_template('home.html')
@app.route('/login')
def login():
return render_template('login.html')
@app.route('/register')
def register():
return render_template('register.html')
if __name__ == '__main__':
app.run(debug=True)
In python terminal I enter the following:
>>> from app import db, app
>>> with app.app_context():
... db.create_all()
Then to check the tables that were created, I exit the python terminal and enter sql terminal via:
sqlite3 database.db
in sqlite terminal:
sqlite> .tables
sqlite>
Im expecting this to return “users” but as you can see there is nothing. Database.db is located in the same directory as app.py