celery异步发邮件常见错误

1、django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM, but settings are not configured. You must either define the environm
ent variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.
解决方案:在tasks里面加入以下代码
import os
import django
os.environ.setdefault(“DJANGO_SETTINGS_MODULE”, “dayfresh.settings”)
django.setup()
2、python manage.py runserver 之前一定要保证celery -A celery_tasks.tasks worker -l info处于运行状态,否则无法发送邮件,若执行ctrl+c则会杀死celery进程,所以要新开一个终端进行runserver

上一篇:Celery异步操作


下一篇:web项目022-----celery的基本使用