Django芹菜错误

时间:2013-05-15 08:09:31

标签: django celery

我一直在尝试安排芹菜在后台做的任务,但我一直遇到问题。

快速参考我迄今为止所做的工作

我通过celery安装了django-celeryeasy_install,添加到INSTALLED_APPS

'djcelery',
'kombu.transport.django',

导入以下内容并运行syncdb:

 import djcelery
 djcelery.setup_loader()
 BROKER_URL = "django://"

我正在尝试在后台运行的任务是密码重置。因此,当用户忘记密码时,我想让发送电子邮件任务在后台运行,所以我所做的就是 我将我的forgot_password函数从views.py移到tasks.py,以便它可以运行。

我的tasks.py

 from django.contrib.auth.views import password_reset
 from django.shortcuts import render
 from celery.decorators import task

 @task()
 def forgot_password(request):
     if request.method == 'POST':
         return password_reset(request,
             from_email=request.POST.get('email'))
     else:
         return render(request, 'forgot_password.html')

他们现在没有views.py

即使问题是,如果我丢失了密码,我也可以发送电子邮件。我不确定它是否在后台运行。我要检查的是:

 manage.py celery worker --loglevel=info

但我收到错误:KeyError: 'processName'

 C:\o\17\mysite>manage.py celery worker --loglevel=info

  -------------- celery@gg-PC v3.0.19 (Chiastic Slide)
 ---- **** -----
 --- * ***  * -- Windows-Vista-6.0.6001-SP1
 -- * - **** ---
 - ** ---------- [config]
 - ** ---------- .> broker:      django://localhost//
 - ** ---------- .> app:         default:0x319c930 (djcelery.loaders.DjangoLoader
 )
 - ** ---------- .> concurrency: 2 (processes)
 - *** --- * --- .> events:      OFF (enable -E to monitor this worker)
 -- ******* ----
 --- ***** ----- [queues]
  -------------- .> celery:      exchange:celery(direct) binding:celery


 [Tasks]
   . accounts.tasks.forgot_password

 [2013-05-15 17:49:45,279: WARNING/MainProcess] C:\Python26\lib\site-packages\dja
 ngo_celery-3.0.17-py2.6.egg\djcelery\loaders.py:133: UserWarning: Using settings
 .DEBUG leads to a memory leak, never use this setting in production environments
 !
   warnings.warn('Using settings.DEBUG leads to a memory leak, never '
 [2013-05-15 17:49:45,292: WARNING/MainProcess] celery@gg-PC ready.
 [2013-05-15 17:49:45,292: INFO/MainProcess] consumer: Connected to django://loca
 lhost//.
 Traceback (most recent call last):
   File "C:\Python26\lib\logging\__init__.py", line 754, in emit
     msg = self.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 637, in format
     return fmt.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 428, in format
     s = self._fmt % record.__dict__
 KeyError: 'processName'
 Traceback (most recent call last):
   File "C:\Python26\lib\logging\__init__.py", line 754, in emit
     msg = self.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 637, in format
     return fmt.format(record)
   File "C:\Python26\lib\logging\__init__.py", line 428, in format
     s = self._fmt % record.__dict__
 KeyError: 'processName'

请有人帮助我,请告诉我忘记密码是否配置为可能在后台发送电子邮件,为什么我会收到此错误KeyError: 'processName'

1 个答案:

答案 0 :(得分:1)

首先,有一种使用芹菜发送电子邮件的简单方法:

django-celery-email

其次,你的任务是错误的。任务是后台工作,而不是视图。它应该执行最后的操作。在您的情况下,这是发送电子邮件