1👍
✅
You seem to be trying to cram too many things into the same view.
What I’d do is the following:
- Create a view that generates the XML (every request to the view should generate the XML from scratch).
- Create a view that uses the timeline widget and points it to the XML in 1)
- Enable Django’s caching layer and annotate the XML view appropriately. E.g.,
@cache_page(60 * 60)
If, for some reason, you need the XML at the time of generation of the HTML (as you seem to indicate in your title), you can just directly call your XML view from the HTML one. E.g.:
@cache_page(..)
def xml(request):
# ... generate xml
def html(request):
xml = xml(request)
# ... generate timeline from xml
Of course, there’s nothing stopping you from manually caching to disk but it’s easier to just use Django’s facilities.
1👍
You don’t need to generate your XML in a view. Just create an XML template, render it to string, and write the result to a temp file.
Source:stackexchange.com