我有一個django項目使用以下目錄結構。Django芹菜目錄結構和佈局
project/
account/
models.py
views.py
blog/
models.py
views.py
mediakit/
models.py
views.py
reports/
celery.py <-- new
models.py
tasks.py <-- new
views.py
settings/
__init__.py <-- project settings file
system/
cron/
mongodb/
redis/
manage.py
這裏的celery.py從芹菜教程(http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html)導出的內容。
from __future__ import absolute_import
import os
from celery import Celery
# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'settings')
from django.conf import settings
# app = Celery('reports')
app = Celery('reports',
backend='djcelery.backends.database:DatabaseBackend',
broker='amqp://guest:[email protected]alhost:5672//')
# Using a string here means the worker will not have to
# pickle the object when using Windows.
app.config_from_object('django.conf:settings')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
@app.task(bind=True)
def debug_task(self):
print('Request: {0!r}'.format(self.request))
我的一些應用程序是跨項目共享的。報告,例如可能在4個不同的項目中使用,所以 我可以看到tasks.py應該如何在報告應用程序中生存,因此當它被添加到新項目 任務時。我不太明白的是,爲什麼celery.py也需要在報告應用程序中生活。當我去添加一些任務到帳戶的應用程序,我基本上建立相同的celery.py文件 用'帳戶'替換'報告'。我不應該有一個芹菜文件與manage.py生活在同一級 嗎?任何幫助或建議將不勝感激。
接受@qwattash回答,因爲它讓我知道我要去哪裏。但這真的是標準嗎?我有系統和設置「應用程序」爲每個項目,celery.py屬於其中之一?看起來這只是一個偏好問題,但如果有一個明確的標準,我想遵循它。 – scoopseven