开发者

Restart Django runserver with file changes

开发者 https://www.devze.com 2023-03-14 08:23 出处:网络
Why does django-admin.py runserver restart if certain files (urls.py)have changed, but not others (template files)?

Why does django-admin.py runserver restart if certain files (urls.py)have changed, but not others (template files)?

Is there a way to specify which files runserver should monitor for changes, and restart if modifications are 开发者_StackOverflow中文版detected?


Because the template files are parsed on each request. They are not loaded in memory. But with .py files it's different as they are loaded in memory when the server starts so a restart is needed to reload them.

LE: runserver checks for changes only in the files that it loads/needs for the app to run. i.e. the settings.py file, ROOT_URLCONF specified in the setting files, the INSTALLED_APPS, etc.

I don't think there is a way to tell it to monitor certain file that is not loaded at runserver. And you wouldn't need that anyway. Why would you want to restart the app for a file that does not affect the execution of your app.


The OP expressed interest in restarting the runserver when template files are changed. It might be helpful to know that you can also force the browser to refresh a view created by templates if you use livereload protocol.

See my answer to this question about reflecting updates to javascript files used by templates to see how to set this up. It involves installing an add-on to the runserver feature in Django.

0

精彩评论

暂无评论...
验证码 换一张
取 消