Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Restart Django runserver with file changes

Tags:

django

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?

like image 802
Mike Avatar asked Jun 18 '11 23:06

Mike


People also ask

How do I change Runserver in Django?

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"

How do you stop a Runserver in Django?

You can Quit the server by hitting CTRL-BREAK.


2 Answers

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.

like image 93
daniels Avatar answered Nov 15 '22 00:11

daniels


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.

like image 28
nmgeek Avatar answered Nov 15 '22 01:11

nmgeek