Answers for "flask where to put db.create_all"

0

flask where to put db.create_all

# This file initializes your application and brings together all of the various components.

# TL;DR: db.create_all(app=app)

from flask import Flask
from .views import mainRoutes	# This just imports my URL-routes
from .extensions import db		# Creates db in another file

app = Flask(__name__)

app.config.from_pyfile('../settings.py')	# Separate file to configure your app

db.init_app(app)
db.create_all(app=app)			# THIS IS THE CRITICAL SOLUTION

app.register_blueprint(mainRoutes)

from DatabaseTest import views # import down here to prevent circular imports
Posted by: Guest on January-13-2022

Python Answers by Framework

Browse Popular Code Answers by Language