Question

What I'm trying to do is use a SIMILE timeline in my Django app. The timeline requires it's data in an XML file. Now, I know how to render a view in html. And I can probably figure out how to render a view into XML. But how would one render both, then pull in the XML data to the HTML file if the XML file doesn't exist on disk (since it is being generated by Django)?

Thanks!

Edit: The line that takes the XML is in Javascript, and looks like this:

Timeline.loadXML("/static/example1.xml", function(xml,url) {eventSource.loadXML(xml,url); })

I need a path, since inserting the XML directly as a string doesn't work. But no path exists, since the XML file never actually exists on disk.

Was it helpful?

Solution

You seem to be trying to cram too many things into the same view.

What I'd do is the following:

  1. Create a view that generates the XML (every request to the view should generate the XML from scratch).
  2. Create a view that uses the timeline widget and points it to the XML in 1)
  3. 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.

OTHER TIPS

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.

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