6

Woking on personal project website with django 1.9 and python 3.4. I am using FullCalendar. The idea is to pass a set of appointment objects into the html page containing the javascript for the calendar. But right now, I am just trying to pass a single default appointment.

In views.py I have the following:

appt = json.dumps({ "title": "meeting", "start": "2016-11-20"});
return render(request, 'healthnet/profile_patient.html', {'patient': patient, 'appt': appt_set})

In profile_patient.html:

<script>

    var data = jQuery.parseJSON("{{appt}}");

    var events;
    events = [];
    events.push(data);


    $(document).ready(function() {

        $('#calendar').fullCalendar({
            editable: true,
            eventLimit: true, // allow "more" link when too many events
            events: events
        });
    });
</script>

appt is not getting properly parsed I believe. When the web page is loaded, the calendar does not display at all.

When I substitute appt with the direct string, it does work:

var data = jQuery.parseJSON('{"title": "meeting", "start": "2016-11-20"}');

When I call alert("{{appt}}"); i get the following:

enter image description here

So there's something wrong with the way I'm using ths varibale. Any ideas?

4
  • so what happens if you do: console.log(data) ?? does it print null? what does it print out? Commented Nov 20, 2016 at 23:43
  • Could you try to change " by '? jQuery.parseJSON('{{appt}}'); ? Commented Nov 20, 2016 at 23:47
  • I uploaded a picture of the alert message. Alert(data) does nothing. And I cant do a console.log. Commented Nov 20, 2016 at 23:49
  • The single quotes didnt change anything unfortunately Commented Nov 20, 2016 at 23:49

1 Answer 1

3

Just use the safe filter:

var data = jQuery.parseJSON('{{appt | safe}}');

n.b. you can also do this

var apptData = {{ appt | safe }};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.