The right place to keep my signals.py file in a Django project

前端 未结 8 873
天涯浪人
天涯浪人 2020-11-27 14:24

Based on Django\'s documentation I was reading, it seems like signals.py in the app folder is a good place to start with, but the problem I\'m facing is that wh

相关标签:
8条回答
  • 2020-11-27 14:50

    To solve your problem you just have to import signals.py after your model definition. That's all.

    0 讨论(0)
  • 2020-11-27 14:54

    If you're using Django<=1.6 I'd recommend Kamagatos solution: just import your signals at the end of your models module.

    For future versions of Django (>=1.7), the recommended way is to import your signals module in your app's config ready() function:

    my_app/apps.py

    from django.apps import AppConfig
    
    class MyAppConfig(AppConfig):
        name = 'my_app'
    
        def ready(self):
            import my_app.signals
    

    my_app/__init__.py

    default_app_config = 'my_app.apps.MyAppConfig'
    
    0 讨论(0)
提交回复
热议问题