-
Notifications
You must be signed in to change notification settings - Fork 1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Cannot Create Database #163
Comments
What is the error you receive? Also please post more code, may it's due to other pages |
The error that I get after attempting to use the sign up page to create a new user is: NameError NameError: name 'db' is not defined My code is as follows: init.py is: `from flask import Flask db = SQLAlchemy() def create_app():
def create_database(app): auth.py is: `from flask import Blueprint, render_template, request, flash, redirect, url_for auth = Blueprint('auth', name) @auth.route('/login', methods=['GET', 'POST']) @auth.route('/logout') logout " @auth.route('/sign-up', methods=['GET', 'POST'])
models.py is: `from . import db class Note(db.Model): class User(db.Model, UserMixin): views.py is: `from flask import Blueprint, render_template views = Blueprint('views', name) @views.route('/') main.py is: `from website import create_app if name == 'main': |
I am admittedly extremely new to Python and coding in general, however, I was following along with this tutorial a day ago and everything was going well up until it came time to create the database.
My code is as follows:
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from os import path'
db = SQLAlchemy()
DB_NAME = "database.db"
def create_app():
app = Flask(name)
app.config['SECRET_KEY'] = 'domine'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}'
db.init_app(app)
def create_database(app):
if not path.exists('website/' + DB_NAME):
db.create_all(app=app)
print('Created Database!')
I have looked over stack overflow and tried a few things here and there, however, I just seem to run into more errors.
At one point what seemed like a database was created in the instance folder of my project, however, it was not named what was expected and I have since been unable to replicate its creation.
The text was updated successfully, but these errors were encountered: