Question

In my application, I am sending periodic cron and background task requests to refresh the cache of pages. While sending a force_refresh kwarg from the view is easy, there's no apparent way to send the force_refresh kwarg to methods being accessed from the template. There are plenty of these I'm using, and it would just make things more complex to start calling all these methods from the view.

So I've been trying to overwrite the template render method so that I pass in the force_refresh kwarg whenever a method is being accessed, if the given response is for a background task request.

I realize that it might simply lead to unexpected problems to add this kwarg to all methods being called, and a try/except ArgumentError block wouldn't exactly be a robust solution, if you have any recommendations about a better way to handle this (hopefully besides accessing each of these methods from the view!), it would be useful to hear them.

Was it helpful?

Solution

Sorry, but your use case is precisely what the view function is for.

In the view function you gather all the data. From this you create a dictionary of the latest data which will be used by the template.

All logic goes in the view. The template has minimal processing.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top