'Blueprint' 对象没有属性 'config'
'Blueprint' object has no attribute 'config'
我正在使用烧瓶邮件。但是当我在 flask 邮件的前端 (react.js) 调用其余的 api 时,我收到了这个错误
'Blueprint' object has no attribute 'config'
这是我的 flask 邮件代码
from flask import Flask,Blueprint
from flask_mail import Mail, Message
app = Blueprint('app', __name__)
app.register_blueprint(url_prefix='/api/v1/SalesLead')
mail=Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'myvar30@gmail.com'
app.config['MAIL_PASSWORD'] = '*****'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(leadHistoryController)
@app.route("/")
def index():
msg = Message('Sheraspace', sender = 'myvar30@gmail.com', recipients = ['jobaer.jhs@gmail.com'])
msg.body = "Hello jh"
mail.send(msg)
return "Sent again"
if __name__ == '__main__':
app.run(debug = True)
有蓝图配置的解决方案吗?或者我可以在前端使用其余 api 而不使用蓝图吗?
必须改用flask.current_app
。
from flask import current_app
def gen_file_name(filename):
"""
If file was exist already, rename it and return a new name
"""
fielname = current_app.config['UPLOAD_FOLDER']
return filename
这里有类似的问题
blueprint-config
我正在使用烧瓶邮件。但是当我在 flask 邮件的前端 (react.js) 调用其余的 api 时,我收到了这个错误
'Blueprint' object has no attribute 'config'
这是我的 flask 邮件代码
from flask import Flask,Blueprint
from flask_mail import Mail, Message
app = Blueprint('app', __name__)
app.register_blueprint(url_prefix='/api/v1/SalesLead')
mail=Mail(app)
app.config['MAIL_SERVER']='smtp.gmail.com'
app.config['MAIL_PORT'] = 465
app.config['MAIL_USERNAME'] = 'myvar30@gmail.com'
app.config['MAIL_PASSWORD'] = '*****'
app.config['MAIL_USE_TLS'] = False
app.config['MAIL_USE_SSL'] = True
mail = Mail(leadHistoryController)
@app.route("/")
def index():
msg = Message('Sheraspace', sender = 'myvar30@gmail.com', recipients = ['jobaer.jhs@gmail.com'])
msg.body = "Hello jh"
mail.send(msg)
return "Sent again"
if __name__ == '__main__':
app.run(debug = True)
有蓝图配置的解决方案吗?或者我可以在前端使用其余 api 而不使用蓝图吗?
必须改用flask.current_app
。
from flask import current_app
def gen_file_name(filename):
"""
If file was exist already, rename it and return a new name
"""
fielname = current_app.config['UPLOAD_FOLDER']
return filename
这里有类似的问题 blueprint-config