Django not updating template files.

Hello,

I installed django with cookie cutter. I’m using docker-compose to run the project on my local machine. When I update the home.html file the change is not reflected in my browser. I cleared the cache and confirmed that DEBUG = TRUE. When I restart docker the change is updated.

However, when I click the side bar, navigate to the templates section / pages and click on home.html the change is shown there. See attached screenshot.

Does anyone know what could be wrong.

I did a clean install of windows just to rule out conflicting apps.

This is the link to github file GitHub - ekul1988/Testing_Django: Testing Django.

Since 4.1, Django now enables the template cache by default. See Django 4.1 release notes | Django documentation | Django. You’d have to change some other file that would cause the process to be restarted to have the modified templates read. Or, set the option to not use the cached loader.

(Also found this useful blog post: Django 4.1+ HTML Templates Are Cached by Default with DEBUG = True — Nick Janetakis)

Thank you! I’m very new at this so I’m not sure how modify the files. I don’t have a settings file. The templates info is in my local.py file. Is it now common practice for people to restart docker whenever they update html or does everyone make a custom modification?

Is this the appropriate way to go about it?

Blockquote
django.core.cache.backends.dummy.DummyCache",
Blockquote

I made the change in my local.py file and teh html files are still not updating.

It might not be named settings.py, but you definitely have a file with the settings in it. (If it’s named local.py, then that’s the file to modify.)

Most people I know don’t directly edit files in containers. They edit the source and rebuild the container.

I see, so it is common practice to make the change then docker compose down, and docker compose up?

It’s a practice, yes, if you’re using the container as a deployment target. (Using docker as a development environment is a different issue.)

Hello, I had the same issue with cookie-cutter-django using docker compose dev container.

I managed to solve the issue by disabling the cache during development (Ken’s comment pointed me in the right direction).

To do this go to the file ./project-name/config/settings/local.py

And add the following:

TEMPLATES[0]["APP_DIRS"] = False
TEMPLATES[0]["OPTIONS"]["loaders"] = [
    "django.template.loaders.filesystem.Loader",
    "django.template.loaders.app_directories.Loader",
]

Then restart the container:

docker compose -f .\docker-compose.local.yml restart django

Now, if you make a change to your templates and press F5, the updated content should be displayed.

I hope this helps.

Kind regards,

Leo