How to avoid AppConfig.ready() method running twice in Django

前端 未结 4 1693
野性不改
野性不改 2020-12-05 06:32

I want to execute some code at startup of Django server but I want it to run only once. Currently when I start the server it\'s executed twice. Documentation says that this

4条回答
  •  猫巷女王i
    2020-12-05 06:48

    When you use python manage.py runserver Django start two processes, one for the actual development server and other to reload your application when the code change.

    You can also start the server without the reload option, and you will see only one process running will only be executed once :

    python manage.py runserver --noreload
    

    You can see this link, it resolves the ready() method running twice in Django

提交回复
热议问题