S
S
Sergey Bondarenko2019-07-02 17:34:25
Python
Sergey Bondarenko, 2019-07-02 17:34:25

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)

Also in this file there is a variable of interest to me - db, which initializes SQLAlchemy.
And as you noticed, I have a blueprint, I need to pass a variable there db, how to do this?
__init__.pyI don’t want to do it, although I think I don’t have much choice ...
If there is any other way, then please tell me about it, thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
German Jet, 2019-07-03
@GeraJet

i need to pass db variable there
where 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 question

Ask a Question

731 491 924 answers to any question