Correct place to put extra startup code in django?

前端 未结 7 1161
深忆病人
深忆病人 2021-01-05 09:20

I would like to run some environment checks when my django process starts and die noisily in the case of an error. I\'m thinking things like the database has an incorrect en

相关标签:
7条回答
  • 2021-01-05 10:08

    I have tested all three __init__.py Settings.py and urls.py methods and this is what I have found.

    When code is run from either __init__.py or Settings.py, the start up functions are run twice upon web server start up; when the start up functions are run from urls.py the code is run once, however it is run only upon the first request made to the we server leading to a potentially long wait for the first user to visit your site.

    It is standard practise to call a 'warming' page when bringing large web applications back online so I don't see that calling a start up function from a CLEARLY identified location in the urls.py should be a problem.

    0 讨论(0)
提交回复
热议问题