import os

from django.apps import apps

from celery import Celery

from .celerybeat_schedule import CELERYBEAT_SCHEDULE


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "{{project_name}}.settings.local")

app = Celery("{{project_name}}_tasks")
app.config_from_object("django.conf:settings", namespace="CELERY")
app.autodiscover_tasks(lambda: [n.name for n in apps.get_app_configs()])
app.conf.update(CELERYBEAT_SCHEDULE=CELERYBEAT_SCHEDULE)

@@ -2,16 +2,27 @@
 mport os
+%0Aimport sys
 %0A%0Afrom d
@@ -70,16 +70,44 @@
 t Celery
+%0Afrom decouple import config
 %0A%0Afrom .
@@ -158,90 +158,369 @@
 LE%0A%0A
-%0Aos.environ.setdefault(%22DJANGO_SETTINGS_MODULE%22, %22%7B%7Bproject_name%7D%7D.settings.local%22
+settings_module = config(%22DJANGO_SETTINGS_MODULE%22, default=None)%0Aif settings_module is None:%0A    print(%0A        %22Error: no DJANGO_SETTINGS_MODULE found. Will NOT start devserver. %22%0A        %22Remember to create .env file at project root. %22%0A        %22Check README for more info.%22%0A    )%0A    sys.exit(1)%0Aos.environ.setdefault(%22DJANGO_SETTINGS_MODULE%22, settings_module
 )%0A%0Aa

Update celery.py