'Celery No hostname was supplied. Reverting to default 'localhost'

I have this in my /var/log/celery/w1.log

enter image description here

I'm following the steps for Celery here.

I have this in my 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', 'sample.settings')

app = Celery('sample2',
            broker='amqp://',
            include=['sample2.tasks'])

# Using a string here means the worker doesn'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')

if __name__ == '__main__':
    app.start()

what can I do to fix this? Thanks in advance.



Solution 1:[1]

Full document in this link.

you should just add the below line to init.py near settings.py

from .celery import app as celery_app

__all__ = ['celery_app']

project structure

- proj/
  - manage.py
  - proj/
    - __init__.py
    - settings.py
    - urls.py

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1