python - app.config()返回keyerror错误怎么回事?

查看:553
本文介绍了python - app.config()返回keyerror错误怎么回事?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问 题

返回的错误:

File "E:\Xflasky\app\auth\views.py", line 79, in resend_confirmation
    'auth/email/confirm', user=current_user, token=token)
  File "E:\Xflasky\app\email.py", line 16, in send_email
    sender=app.config['FLASK_MAIL_SENDER'], recipients=[to])
KeyError: 'FLASK_MAIL_SENDER'

这是email.py

def send_email(to, subject, template, **kwargs):
    app = current_app._get_current_object()
    msg = Message(app.config['FLASKY_MAIL_SUBJECT_PREFIX'] + subject,
                  sender=app.config['FLASK_MAIL_SENDER'], recipients=[to])
    msg.body = render_template(template + '.txt', **kwargs)
    msg.html = render_template(template + '.html', **kwargs)
    thr = Thread(target=send_async_email, args=[app, msg])
    thr.start()
    return thr

这是config.py

class Config:
    SECRET_KEY = os.environ.get('SECRET_KEY') or 'hard to guess string'
    SQLALCHEMY_COMMIT_ON_TEARDOWN = True
    FLASKY_MAIL_SUBJECT_PREFIX = '[XFlasky]'
    FLASKY_MAIL_SENDER = 'XXXXX@123.com'
    FLASKY_ADMIN = os.environ.get('FLASKY_ADMIN')
    MAIL_SERVER = 'smtp.163.com'
    MAIL_PORT = 25
    MAIL_USE_TLS = True
    MAIL_USERNAME = os.environ.get('MAIL_USERNAME')
    MAIL_PASSWORD = os.environ.get('MAIL_PASSWORD')
    
    @staticmethod
    def init_app(app):
        pass

解决方案

少个 'Y'

这篇关于python - app.config()返回keyerror错误怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆