我最近开始使用带有django的rabbitmq和芹菜。我正在使用django-celery,django-celery-email和邮局以异步方式发送电子邮件。 安装所有这些软件包后,我的settings.py看起来像
INSTALLED_APPS = [
#other apps
'djcelery',
'djcelery_email',
'post_office'
]
# setup celery
import djcelery
djcelery.setup_loader()
# using post office as the default email backend
EMAIL_BACKEND = 'post_office.EmailBackend'
# using djcelery's email backend as a backend for post office
POST_OFFICE_BACKEND = 'djcelery_email.backends.CeleryEmailBackend'
POST_OFFICE = {
'DEFAULT_PRIORITY' : 'now'
}
EMAIL_HOST = 'YOUR_HOST_NAME'
EMAIL_HOST_USER = "YOUR_HOST_USER_NAME"
EMAIL_PORT = 25 # default smtp port
EMAIL_HOST_PASSWORD = "YOUR_HOST_USER_PASSWORD"
EMAIL_USE_TLS = False
DEFAULT_FROM_EMAIL = 'testing@example.com'
当我试图通过命令
运行django-celery时**python manage.py celeryd**
正在通过以下错误
Traceback (most recent call last):
File "manage.py", line 22, in <module>
execute_from_command_line(sys.argv)
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 364, in execute_from_command_line
utility.execute()
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 356, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 206, in fetch_command
klass = load_command_class(app_name, subcommand)
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 40, in load_command_class
module = import_module('%s.management.commands.%s' % (app_name, name))
File "/usr/lib/python2.7/importlib/__init__.py", line 37, in import_module
__import__(name)
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/djcelery/management/commands/celeryd.py", line 16, in <module>
class Command(CeleryCommand):
File "/home/ubuntu/edyodavirtual/local/lib/python2.7/site-packages/djcelery/management/commands/celeryd.py", line 20, in Command
worker.get_options() +
TypeError: can only concatenate tuple (not "NoneType") to tuple
此处有人帮我解决此问题
答案 0 :(得分:1)
即使我面临同样的问题,我也试图通过djcelery包将芹菜与django整合在一起。然后我阅读了许多博客和文档,并在下面得出结论。
“Celery的早期版本需要一个单独的库来处理Django,但是从3.1开始就不再是这样了。现在支持Django”
[芹菜笔记] [1] http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html
没有使用djcelery我直接编写任务并且它有效!
答案 1 :(得分:0)
只需在“〜/ anaconda2 / envs / test_django / lib / python3.6 / site-packages / djcelery / management / commands / celery.py”中注释掉这些行,就像这样:
14 # options = (CeleryCommand.options +
15 # base.get_options() +
16 # base.preload_options)
然后它起作用。