From 23d114f6d99f763a1fafe88b581f52370e567620 Mon Sep 17 00:00:00 2001 From: royord Date: Sat, 14 Jan 2023 17:20:10 -0800 Subject: [PATCH 1/2] fixed for issues with python 3.10 --- app.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app.py b/app.py index e65aa9b..2e01689 100644 --- a/app.py +++ b/app.py @@ -1,3 +1,4 @@ +import os from flask import Flask, render_template, url_for, redirect from flask_sqlalchemy import SQLAlchemy from flask_login import UserMixin, login_user, LoginManager, login_required, logout_user, current_user @@ -6,12 +7,18 @@ from wtforms.validators import InputRequired, Length, ValidationError from flask_bcrypt import Bcrypt +from sqlalchemy.sql import func + +basedir = os.path.abspath(os.path.dirname(__file__)) + app = Flask(__name__) -db = SQLAlchemy(app) bcrypt = Bcrypt(app) -app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' +app.config['SQLALCHEMY_DATABASE_URI'] =\ + 'sqlite:///' + os.path.join(basedir, 'database.db') +# app.config['SQLALCHEMY_DATABASE_URI'] = 'sqlite:///database.db' +app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False app.config['SECRET_KEY'] = 'thisisasecretkey' - +db = SQLAlchemy(app) login_manager = LoginManager() login_manager.init_app(app) @@ -101,4 +108,4 @@ def register(): if __name__ == "__main__": - app.run(debug=True) + app.run(debug=True, host="0.0.0.0") From a1859f5d4271bed97d1dd0828d67919011c4f86e Mon Sep 17 00:00:00 2001 From: royord Date: Sat, 14 Jan 2023 17:35:28 -0800 Subject: [PATCH 2/2] Commands for creating database. Commands for creating the database needed to be document, they have changed in more recent versions of python. --- README.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/README.md b/README.md index 66971d0..6905f8d 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,15 @@ This repository contains the code used in the Python Flask Authentication [video](https://www.youtube.com/watch?v=71EU8gnZqZQ) uploaded on [my YouTube channel](https://www.youtube.com/watch?v=71EU8gnZqZQ). +If on python 3.10 plus the following commands may be needed to create/recreate the database file. +``` +export FLASK_APP=app +flask shell # this instead of python3 (python shell) +from app import db,app +db.drop_all() +db.create_all() +``` + ## Installation Use the package manager [pip](https://pip.pypa.io/en/stable/) to install the required dependencies