[Django]-Django prevent caching of included html fragment

3👍

2👍

I’m assuming you’re aware of template fragment caching – I don’t believe setting a lower value here will override a view-level cache set to a longer period, though. This of course would mean you’d have to cache different parts of your index.html separately, which is feasible but not likely what you want.

You might also look at the clearcache tag for template fragments implemented here.

👤Eric P

1👍

You can’t, really. When you cache the whole view, Django doesn’t process it at all. It just returns the same response from the cache, which includes the fully formed HTML. You can add vary headers to the cache, but that won’t help you unless there’s something to vary on (logged in user, etc.). It won’t help with just a basic block of changing content not tied to anything else.

Remove the view-level caching and manually cache things in the view that you want. Otherwise, you’re out of luck.

Leave a comment