I noticed that ./manage.py runserver
automatically reloads when my views.py
file is changed. How doesthe underlying code that drives it work?
Automatic Django Server Restart:
Django tries to poll file modification timestamps each second. If it sees there are any changes. it restarts the server.
So basically, Django server checks every second the modification timestamps of every file. If it sees a change in any of them, it will trigger a server restart.
However, adding a new file does not trigger a restart so you will have to restart the server yourself in that scenario.
Exception: If you are using Linux
and install pyinotify
, kernel signals will be used to autoreload the server.
As per django docs,
If you are using
Linux
and installpyinotify
, kernel signals will be used to autoreload the server (rather than polling file modification timestamps each second). This offers better scaling to large projects, reduction in response time to code modification, more robust change detection, and battery usage reduction.
System Checks performed while restarting the server:
System check framework is used to perform checks on Django projects.
The system check framework is a set of static checks for validating Django projects. It detects common problems and provides hints for how to fix them.
When you start the server, and each time you change Python code while the server is running, the system check framework checks our entire Django project for some common errors. If any errors are found, they are printed to standard output.
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