Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

341
Visualizações
Django: Celery can't find my app
ModuleNotFoundError: No module named 'myapp'

I'm not really understanding what the problem is here. There are no issues with my app, but celery can't seem to find it no matter what I try and change.

Here is my directory structure:

django
 / mysite
     __init__.py
     celery.py
     settings.py
     urls.py
     wsgi.py
     / myapp
       admin.py
       apps.py
       models.py
       tasks.py
       urls.py
       views.py
   manage.py

celery.py:

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

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

app = Celery('myapp')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


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

Command: celery -A myapp worker -l info

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

Make sure that your init.py file contains the following:

from __future__ import absolute_import, unicode_literals

# This will make sure the app is always imported when
# Django starts so that shared_task will use this app. from .celery_worker import app as celery_app

__all__ = ['celery_app']

Also, make sure that your celery.py looks something along the lines of this

from __future__ import absolute_import, unicode_literals
import os
from celery import Celery
from celery.schedules import crontab
import mysite

# set the default Django settings module for the 'celery' program.
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'mysite.settings')

app = Celery('wellfie')

# Using a string here means the worker don't have to serialize
# the configuration object to child processes.
# - namespace='CELERY' means all celery-related configuration keys
#   should have a `CELERY_` prefix.
app.config_from_object('django.conf:settings', namespace='CELERY')

# Load task modules from all registered Django app configs.
app.autodiscover_tasks()


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

Make sure that your tasks are properly recognized as well: for instance a shared task would look like

@shared_task(name="mysite.myapp.tasks.simple_task") Edit.

Actually you need to move the myapp out of mysite and into the Django folder. I would rename the Django folder to mysite as well, so that you have the parent folder mysite, child folder mysite, that holds wsgi, celery, settings etc, child folder myapp

over 4 years ago · Santiago Trujillo Relatório

0

Your celery.py file should be in myapp folder. (http://docs.celeryproject.org/en/latest/django/first-steps-with-django.html)

You should run celery -A myapp worker -l info in mysite folder.

over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda