def __call__(self, *args, **kwargs): with app.app_context(): return TaskBase.__call__(self, *args, **kwargs)
def sendemail(recvemail, r): with app.app_context(): msg = Message("邮箱验证码", recipients=[recvemail], body="验证码为" + r) mail.send(msg)
def decorated_function(*args, **kwargs): with app.app_context(): g.mongo = app_mongo g.redis = app_redis return function(*args, **kwargs)
def setmail(data, r): with app.app_context(): msg = Message("我的邮箱验证码", recipients=[data], body="验证码为" + r) mail.send(msg)
def setphone(data, rs): with app.app_context(): r = send_sms(phone_numbers=data, smscode=rs)
from celery_app import celery, app from model.db import db db.init_app(app) if __name__ == '__main__': with app.app_context(): celery.start()