我正在我们的烧瓶应用程序中实现烧瓶邮件,但无法摆脱应用程序耗尽上下文错误。任何帮助,将不胜感激。我已将 mail_server 参数放在配置文件中。
/app.py - 应用在 create_web_apis 中实例化
def create_app(config):
"""Creates an instance of the app according to `config`
:param config: An instance of :class:`flask.config.Config`
:returns: The configured application. This can be passed to a WSGI
container.
"""
app = create_web_apis()
app.config.update(config)
mail = Mail(app)
...
/电子邮件.py
from flask import current_app
from flask.ext.mail import Mail, Message
mail = Mail(current_app)
def send_email(subject, sender, recipients, text_body, html_body):
msg = Message(subject, sender = sender, recipients = recipients)
msg.body = text_body
msg.html = html_body
mail.send(msg)
这是完整的跟踪
Traceback (most recent call last):
File "bin/run-tests", line 58, in <module>
test_suite = test_loader.loadTestsFromNames(args.tests)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 128, in loadTestsFromNames
suites = [self.loadTestsFromName(name, module) for name in names]
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/unittest/loader.py", line 91, in loadTestsFromName
module = __import__('.'.join(parts_copy))
File "/Users/tahsin/dev/restful_phollow/phollow/tests/test_external.py", line 16, in <module>
from phollow.emails import send_email
File "/Users/tahsin/dev/restful_phollow/phollow/emails.py", line 6, in <module>
mail = Mail(current_app)
File "/Users/tahsin/dev/venv/phollow/lib/python2.7/site-packages/flask_mail.py", line 461, in __init__
self.state = self.init_app(app)
File "/Users/tahsin/dev/venv/phollow/lib/python2.7/site-packages/flask_mail.py", line 473, in init_app
app.config.get('MAIL_SERVER', '127.0.0.1'),
File "/Users/tahsin/dev/venv/phollow/lib/python2.7/site-packages/werkzeug/local.py", line 338, in __getattr__
return getattr(self._get_current_object(), name)
File "/Users/tahsin/dev/venv/phollow/lib/python2.7/site-packages/werkzeug/local.py", line 297, in _get_current_object
return self.__local()
File "/Users/tahsin/dev/venv/phollow/lib/python2.7/site-packages/flask/globals.py", line 26, in _find_app
raise RuntimeError('working outside of application context')