S
S
Spoon in the brain2019-06-17 15:20:25
MySQL
Spoon in the brain, 2019-06-17 15:20:25

How to import a variable in blueprint?

Good afternoon!
In general, I created a blueprint (root) with all routers, after which I created a connection to the database, now I need to somehow use this connection in the root blueprint.
db.py

from flaskext.mysql import MySQL
from config import app


mysql = MySQL()
app.config['MYSQL_DATABASE_USER'] = 'root'
app.config['MYSQL_DATABASE_PASSWORD'] = 'root'
app.config['MYSQL_DATABASE_DB'] = 'telebot'
app.config['MYSQL_DATABASE_HOST'] = 'localhost'
mysql.init_app(app)

config.py
from flask import Flask
from termcolor import colored

from source.root import root 
from db import *


app = Flask(__name__, template_folder = 'assets', static_folder='static', static_url_path='/static/admin')


app.register_blueprint(root)


if __name__ == '__main__':
  app.secret_key = 'key'
  print(colored(' * Application started successfully!', 'blue'))
  app.run(debug = True)

How to pass a variable mysqlto root?
Or is there another way?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
P
pcdesign, 2019-06-18
@vessels

In the root file

from flask import current_app as app

MYSQL_DATABASE_USER = app.config.get('MYSQL_DATABASE_USER')
print(MYSQL_DATABASE_USER)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question