1

Long story short, I need to call a python script from a Celery worker using subprocess. This script interacts with a REST API. I would like to avoid hard-coding the URLs and django reverse seems like a nice way to do that.

Is there a way to use reverse outside of Django while avoiding the following error?

django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet.

I would prefer something with low-overhead.

luederm
  • 21
  • 4

2 Answers2

0

As documented

If you’re using components of Django “standalone” – for example, writing a Python script which loads some Django templates and renders them, or uses the ORM to fetch some data – there’s one more step you’ll need in addition to configuring settings.

After you’ve either set DJANGO_SETTINGS_MODULE or called configure(), you’ll need to call django.setup() to load your settings and populate Django’s application registry.

iklinac
  • 14,944
  • 4
  • 28
  • 30
0

I am using a custom manager command to boot my django app from external scripts. It is like smashing a screw with a hammer, but the setup is fast and it takes care for pretty much everything.

tstoev
  • 1,415
  • 11
  • 12