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 detected?
Inside the commands folder open up the runserver.py script with a text editor. Find the DEFAULT_PORT field. it is equal to 8000 by default. Change it to whatever you like DEFAULT_PORT = "8080"
You can Quit the server by hitting CTRL-BREAK.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With