I've used django dev servers for years. I start them with
python manage.py runserver
and when I change any of the python code, they restart nicely.
Now I've inherited someone else's project for maintenance, and for whatever reason, I change the Python code and the server does not restart. I can't seem to find any kind of configuration option that would cause this.
I don't have the --noreload flag set, here's my proof:
$ ps -ef | grep runserver
chris 290898 250765 1 11:55 pts/6 00:00:00 python manage.py runserver
chris 290914 290898 5 11:55 pts/6 00:00:01 /home/chris/.virtualenvs/my-webapp-4cLYw-9X/bin/python manage.py runserver
Has anyone run into this before?
UPDATE
More info...equally as odd
the project is set up like this
src/manage.py
src/myproject (contains settings.py, urls.py, etc)
src/apps/app_one (contains models.py, tests.py, etc)
src/apps/app_two (contains models.py, tests.py, etc)
If I edit any file under src/myproject, then the server restarts as expected. But if I edit files under app_one or app_two, then the server does not restart.
UPDATE #2
Resurrecting this before it drives me crazy (it may be too late).
I added django.utils.autoreload': {'level': 'DEBUG'}, to settings.LOGGING, and now I can see that Django is watching my files, because I can see this in the logs:
[15/Feb/2022 10:58:14] django.utils.autoreload - DEBUG [tick:392] File /home/chris/OBFUSCATED/src/apps/account/models.py previous mtime: 1644940666.8954673, current mtime: 1644940693.9396086
[15/Feb/2022 10:58:14] django.utils.autoreload - DEBUG [notify_file_changed:366] /home/chris/OBFUSCATED/src/apps/account/models.py notified as changed. Signal results: [(<function template_changed at 0x7efd4b77b550>, True), (<function translation_file_changed at 0x7efd48257f70>, None)].
And yet, the dev server does not restart. Hoping this makes more sense to someone than it does to me.
UPDATE
This is fixed in Django 3.2.13 and Django 4.0.4
Original answer
I have a similar issue, and it appears to be a bug. I tracked it down to Django 3.2.4 (3.2.3 works as expected).
See the Release notes for Django 3.2.4. This is the bugfix that breaks it for me.
It's still broken as of 4.0.3.
UPDATE
In my case this is due to having [''] in DIRS, use filter if you are getting the value from the enviroment:
TEMPLATES = [
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": filter(None, os.getenv("TEMPLATES_DIRS", "").split(",")),
...
I've opened a bug and a PR
Have had the same issue. I finally identified the issue. In my settings.TEMPLATES, the DIRS was [BASE_DIR], while it should be [BASE_DIR / 'templates'].
Once I fixed this, autoreload worked again.
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