When I make a modification in a python source file in my project, Django detects that and restart runserver itself. But when I modify a django template, I have to kill runserver and restart it again : how can I do to have runserver restart automatically on template change ?
The file will by default be read from disk on every request, so there is no need to restart anything.
There is a caching template loader, but it is disabled by default. See the documentation for more info.
Run touch
against one of the Python source files.
Because runserver
monitors .py files for changes, it does not restart for a change in the templates (.html). You can trigger this restart by virtually editing any of the .py files using the touch
command, which refreshes its date modified and leaves all the other contents the same.
Another solution is to make sure you have debug
set to true inside of you TEMPLATES
config in settings.py
DEBUG = True
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': ['templates/'],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
'debug': DEBUG,
},
},
]
When debug
is False you have to manually restart the server to see any changes made to templates (since they don't automatically trigger a restart)
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