django报错:django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM 处理办法

django框架中,注册页面使用celery异步发送邮件, 在执行
celery -A celery_tasks.tasks worker -l info 之后, 正常显示,
但在注册页面点击注册后, 报错如下:
django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM, but settings are not configured. You must either define the environment variable DJANGO_SETTINGS_MODULE or call settings.configure() before accessing settings.

解决方法:

在任务处理者一端添加如下几行代码:
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE","dailyfresh.settings")
django.setup()

注: celery任务的发出者,中间人,任务的处理者, 既可以在同一台电脑上, 也可以在不同的电脑上. (发出者与处理者的其它代码完全相同)

django报错:django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM 处理办法_第1张图片
在这里插入图片描述
django报错:django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM 处理办法_第2张图片
django报错:django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM 处理办法_第3张图片
django报错:django.core.exceptions.ImproperlyConfigured: Requested setting EMAIL_FROM 处理办法_第4张图片

你可能感兴趣的:(工具类)