Auto-reload server when saving component file #567
-
Is it just me or does the Django auto-reload watcher not pick up changes in the components .py files to reload the server when making changes? Not the end of the world but pretty annoying when developing. |
Beta Was this translation helpful? Give feedback.
Replies: 3 comments 6 replies
-
@twm-jamieb Could it be the same problem as is being discussed here? #423 |
Beta Was this translation helpful? Give feedback.
-
I had similar issue in my project. Googling around it, I found that Django dev server reloads only when top-level template files change. So if you define each component as a directory, then dev server doesn't reload when the files change. I used following workaround to make Django reload dev on file changes by adding the files to watch list for our nested templates. See https://stackoverflow.com/a/66673186/9788634. But, frankly, this still doesn't work 100%, and maybe 5% of the time still I have to hit For context, in this case Django runs in Docker, and dev server is started with from glob import glob
from pathlib import Path
from django.apps import AppConfig
from django.conf import settings
from django.utils.autoreload import autoreload_started
class HomeConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'home'
def ready(self):
# APP_ENV is a custom variable set in settings.py that describes the env
if settings.APP_ENV == "local":
watch_list = [
# Find all nested template files
*glob('./home/templates/**/*', recursive=True),
*glob('./project/templates/**/*', recursive=True),
*glob('./components/**/*', recursive=True),
]
watch_files_for_autoreload(watch_list)
def watch_files_for_autoreload(watch_list: list[str]):
def autoreload_hook(sender, *args, **kwargs):
watch = sender.extra_files.add
for file in watch_list:
watch(Path(file))
autoreload_started.connect(autoreload_hook) |
Beta Was this translation helpful? Give feedback.
-
Closing this one, this has been released as part of https://github.com/EmilStenstrom/django-components/releases/tag/0.94. See Reload dev server on component file changes |
Beta Was this translation helpful? Give feedback.
Closing this one, this has been released as part of https://github.com/EmilStenstrom/django-components/releases/tag/0.94. See Reload dev server on component file changes