ImportError: cannot import name 'mail'一直在报错,请问老师该怎么解决啊
来源:12-11 异步发送电子邮件
怕几眼
2019-04-03
from app import mail
from threading import Thread
from flask_mail import Message
from flask import current_app, render_template
def send_async_email(app, msg):
with app.app_context():
try:
mail.send(msg)
except Exception as e:
pass
def send_mail(to, subject, template, **kwargs):
# Python email
# msg = Message('测试邮件', sender='aaa@qq.com', body='Test',
# recipients=['user@qq.com'])
msg = Message('[鱼书]' + ' ' + subject,
sender=current_app.config['MAIL_USERNAME'],
recipients=[to])
msg.html = render_template(template, **kwargs)
# current_app app = Flask()
app = current_app._get_current_object()
thr = Thread(target=send_async_email, args=[app, msg])
thr.start()
from flask import Flask
from flask_login import LoginManager
from app.models.book import db
from flask_mail import Mail
login_manager = LoginManager()
mail = Mail()
def create_app():
app = Flask(name)
app.config.from_object(‘app.secure’)
app.config.from_object(‘app.setting’)
register_blueprint(app)
db.init_app(app)
login_manager.init_app(app)
login_manager.login_view = 'web.login'
login_manager.login_message = '请先登录或注册'
mail.init_app(app)
with app.app_context():
db.create_all()
return app
def register_blueprint(app):
from app.web.book import web
app.register_blueprint(web)
写回答
1回答
-
7七月
2019-04-04
具体是报什么错误呢?只能看到错误 才能大概猜到是什么原因。
032019-04-05
相似问题