django.core.exceptions.ImproperlyConfigured:请求的设置DEFAULT_INDEX_TABLESPACE

时间:2018-12-03 06:14:20

标签: python django celery

帮我解决错误

- django_celery/
    - my_app/
        - __init__.py
        - task.py
    - proj/
        - __Init__.py
        - celery.py
        - settings.py
    - manage.py

proj / init.py:

from __future__ import absolute_import, unicode_literals
from .celery import app as celery_app

__all__ = ('celery_app',)

proj / celery.py:

from __future__ import absolute_import,unicode_literals
import os
from celery import Celery
from django.conf import settings
from django_celery_beat.models import PeriodicTasks

os.environ.setdefault('DJANGO_SETTINGS_MODULE','proj.settings')
app = Celery('proj')

app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)

proj / settings.py:

import os
os.urandom(24)

SECRET_KEY = os.urandom(24)

BROKER_URL = 'redis://localhost:6379/0'
CELERY_RESULT_BACKEND = 'redis://localhost:6379/0'
CELERY_ACCEPT_CONTENT = ['application/json']
CELERY_RESULT_SERIALIZER = 'json'
CELERY_TIMEZONE = 'Asia/Seoul'

CELERY_BEAT_SCHEDULE = {
 'task-number-one': {
        'task': 'my_app.tasks.add',
        'schedule': 10,
        'args': (10,5)
    },
}
INSTALLED_APPS = (
     'django_celery_beat',
)

my_app / task.py

from __future__ import absolute_import,unicode_literals
from celery import shared_task,task

@task
def add(x, y):
    return x + y

我遇到错误: django.core.exceptions.ImproperlyConfigured:请求的设置为DEFAULT_INDEX_TABLESPACE,但未配置设置。在访问设置之前,您必须定义环境变量DJANGO_SETTINGS_MODULE或调用settings.configure()。

0 个答案:

没有答案