1

I am using flask-mail. But when i call the rest api in front end(react.js) of flask mail i am getting this error

'Blueprint' object has no attribute 'config'

Here is my code for flask mail

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)

Is there any solution for blueprint config? Or can i use the rest api in front end without using blueprint?

jobaer sourav
  • 87
  • 1
  • 8

1 Answers1

6

Must use flask.current_app instead.

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

There is similar question here blueprint-config

SO Stinks
  • 3,258
  • 4
  • 32
  • 37
user2849045
  • 76
  • 1
  • 4