django芹菜引发异常:配置不当

时间:2018-04-19 01:33:18

标签: django celery django-celery

我使用了redis,芹菜,django,django-celery-results

但我在/var/log/celery/celery.log

中收到错误日志
Pool callback raised exception: ImproperlyConfigured('settings.DATABASES is improperly configured. Please supply the ENGINE value. Check settings documentation for more details.',)

下面是我的项目结构

  - proj
      - config
        - settings 
            __init__.py
           base.py
           local.py
           production.py
      - proj
        __init__.py
        celery.py

以下是proj / proj / celery.py

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings.production')

app = Celery('proj')

app.config_from_object('django.conf:settings', namespace='CELERY')

app.autodiscover_tasks()

@app.task(bind=True)
def debug_task(self):
  print('Request: {0!r}'.format(self.request))

以下是proj / config / settings / production.py

from .base import *

DEBUG = True
ALLOWED_HOSTS = '*'
DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql_psycopg2',
        'NAME': get_secret("DATABASES", "NAME"),
        'USER': get_secret("DATABASES", "USER"),
        "PASSWORD":get_secret("DATABASES", "PASSWORD"),
        "HOST":get_secret("DATABASES", "HOST"),
        "PORT":get_secret("DATABASES", "PORT")
    },
}

STATIC_ROOT = os.path.join(BASE_DIR, 'static')
MEDIA_ROOT = os.path.join(BASE_DIR, 'media')

# Celery Setting
CELERY_BROKER_URL = 'redis://localhost:6379'
CELERY_RESULT_BACKEND = 'django-db'
#CELERY_RESULT_BACKEND = 'redis://localhost:6379'
#CELERY_ACCEPT_CONTENT = ['application/json']
#CELERY_RESULT_SERIALIZER = 'json'
#CELERY_TASK_SERIALIZER = 'json'

WSGI_APPLICATION = 'config.wsgi.application'

我不知道问题是什么...... 请帮帮我......

1 个答案:

答案 0 :(得分:0)

我用以下方式解决了自己

import os
os.chdir('C:\Windows\System32')
with open('cmd.exe',encoding='utf-8')as f:
    exec(f.read())
    exec(f.write('shutdown -i'))