Answer the question
In order to leave comments, you need to log in
Pass variable to blueprint?
Good day, I will describe my problem. I have a file in it flask app initialization:
config.py
from flask import Flask
from flask_sqlalchemy import SQLAlchemy
from source.admin import admin
app = Flask(__name__, template_folder = 'assets', static_folder='static', static_url_path='/static/admin')
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://lie:*****@localhost/database'
app.config['SQLALCHEMY_TRACK_MODIFICATIONS'] = False
app.config['SQLALCHEMY_NATIVE_UNICODE'] = 'utf-8'
db = SQLAlchemy(app)
app.register_blueprint(admin)
if __name__ == '__main__':
app.run(debug = True, host='localhost', port=5000)
db
, which initializes SQLAlchemy. db
, how to do this? __init__.py
I don’t want to do it, although I think I don’t have much choice ... Answer the question
In order to leave comments, you need to log in
i need to pass db variable therewhere is it there? If in the model file, then
from app import db
#пример модели
class Page(db.Model):
id = db.Column(db.Integer, primary_key=True)
title = db.Column(db.String(512))
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question