Skip to content

Instantly share code, notes, and snippets.

@Kd-Here
Created March 4, 2023 19:45
Show Gist options
  • Save Kd-Here/0b6e8a6fcc7c44a702882ba738031c84 to your computer and use it in GitHub Desktop.
Save Kd-Here/0b6e8a6fcc7c44a702882ba738031c84 to your computer and use it in GitHub Desktop.
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'] = 'fdadjfaoef afdpp'
app.config['SQLALCHEMY_DATABASE_URI'] = f'sqlite:///{DB_NAME}' #This stores sqlite database in current dir
db.init_app(app) #This show what is app our database is storing
from .views import views
from .auth import auth
app.register_blueprint(views,url_prefix='/')
# app.register_blueprint(auth,url_prefix='/auth/') #What's different between both this here before every url it must /auth/ then what you want
app.register_blueprint(auth,url_prefix='/') #It will be / only no prefix-> before url
from .models import User,Note
create_database()
return app
def create_database():
if not path.exists('website/'+DB_NAME):
print("Created Database!")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment