Python,Django, Bootstrap, fullcalendar
如何把 fullcalendar 中的 Events 静态参数替换为数据库取出的结果?求帮忙解答一下
- Script 中替换代码怎么写?
- url: "{% url 'get_calendar_list' %}"
- Django View 怎么返回?直接返回 HttpResponse 就可以吗?

def get_calendar_list(request):
calendar_list = CalendarEvent.objects.all()
return HttpResponse(calendar_list)
<div class="col-md-10">
<div id='calendar'></div>
</div>
<script type="text/javascript" src="js/full-calendar/fullcalendar.js"></script>
<script>
$(document).ready(function() {
/* initialize the external events
-----------------------------------------------------------------*/
$('#external-events .fc-event').each(function() {
// store data so the calendar knows to render an event upon drop
$(this).data('event', {
title: $.trim($(this).text()), // use the element's text as the event title
stick: true // maintain when user navigates (see docs on the renderEvent method)
});
// make the event draggable using jQuery UI
$(this).draggable({
zIndex: 999,
revert: true, // will cause the event to go back to its
revertDuration: 0 // original position after the drag
});
});
/* initialize the calendar
-----------------------------------------------------------------*/
$('#calendar').fullCalendar({
header: {
left: 'prev,next today',
center: 'title',
right: 'month,basicWeek,basicDay'
},
defaultDate: '2015-02-12',
editable: true,
droppable: true, // this allows things to be dropped onto the calendar
eventLimit: true, // allow "more" link when too many events
events: [
{
title: 'All Day Event',
start: '2015-02-01',
color: '#9A80B9'
},
{
title: 'Long Event',
start: '2015-02-07',
end: '2015-02-10',
color: '#EF4836'
},
{
id: 999,
title: 'Repeating Event',
start: '2015-02-09T16:00:00'
}
]
});
});
</script>