문제

I think this is less related to using Timeline and more how I'm building my JSON object.

I have a template containing a Simile Timeline widget. All is well When the data is hard coded into the template but that's no fun...

Here's how I'm building the JSON events and passing it to the view.

View

def load_timeline_events(request):
  raw_events = [{
      "title" : "Data",
      "color" :"red",
      "start" : "0020-01-01",
      "end" : "0022-01-01",
      "description" : "20 - 22"
    },
    {
      "title" : "Log",
      "color" :"blue",
      "start" : "0002-01-01",
      "end" : "0016-01-01",
      "description" : "2 - 16"
    }]
return render('timeline.html', {'EVENTS':json.dumps(raw_events)})

Template

load_events : function() {
    timeline.events.loadJSON({
        "events" : {{ EVENTS }},
        "dateTimeFormat" : "iso8601"
    }, timeline.base_uri);
},

No error returned, just a blank Timeline box.

도움이 되었습니까?

해결책

Need to cast as SafeString before passing the dictionary to the template. No need to use the json module.

Same problem as found here: Using JSON in django template

View

from django.utils.safestring import SafeString
...
def load_timeline_events(request):
    ....
    return render('timeline.html', {'EVENTS':SafeString(raw_events)})
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top