Execute code when Django starts ONCE only?

前端 未结 7 1393
终归单人心
终归单人心 2020-11-22 13:55

I\'m writing a Django Middleware class that I want to execute only once at startup, to initialise some other arbritary code. I\'ve followed the very nice solution posted by

7条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-22 14:38

    If it helps someone, in addition to pykler's answer, "--noreload" option prevents runserver from executing command on startup twice:

    python manage.py runserver --noreload
    

    But that command won't reload runserver after other code's changes as well.

提交回复
热议问题