Where to put the django signal receiver code, distribute them to several files?

I put the signal receiver code in the corresponding model file.

However, signal receivers continue to grow, and I would like to split them into several files.

I have not seen a discussion about where to put the signal receiver codes.

(makes me suspect that I should not do many signal receivers, maybe?)

+5
source share
2 answers

See docs:
https://docs.djangoproject.com/en/1.8/topics/signals/#connecting-receiver-functions

signals.py, , , , , .

, Django 1.7+ AppConfig.ready

:
http://chriskief.com/2014/02/28/django-1-7-signals-appconfig/

( , )

# myapp/__init__.py
default_app_config = 'myapp.apps.MyAppConfig'

# myapp/apps.py
from django.apps import AppConfig

class MyAppConfig(AppConfig):

    name = 'myapp'
    verbose_name = 'My App'

    def ready(self):

        # import signal handlers
        import myapp.signals.handlers
+9

django, , WSGI (django.core.wsgi) django.setup()

-

, fooobar.com/questions/51488/... @classmethod

0

All Articles