Skip to content

Getting fullcalendar javascript click data to django modelform

i want to click event on Fullcalendar, then it open another page, like this

    document.addEventListener('DOMContentLoaded', function() {
        var calendarEl = document.getElementById('calendar');
        var calendar = new FullCalendar.Calendar(calendarEl, {
            dateClick: function(info) {
      "{% url 'create-book' %}","_self");

. but how to get data from fullcalendar ? there are function dateStr for show date, and, to show resource in timeline view(fullcalendar)

 alert('clicked ' + info.dateStr + ' on resource ' +;           

. what i want is bring dateStr and clicked data to django modelform,


def create_book(request):
    booking_forms = BookingForm(initial={

im not sure what should i put on xxxx to get this through url on other page..



In any web application, if you want to pass data to another page, you generally add it to the URL in some way.

e.g. something like /create_book?resourceId=123&startdate=2021-02-18.

So in your case I’d expect something like"{% url 'create-book' %}?resourceId=" + encodeURIComponent( + "&startdate=" + encodeURIComponent(info.dateStr),"_self");

would be needed on the client-side, and

def create_book(request):
    booking_forms = BookingForm(initial={
        'resourceId': request.GET.get('resourceId'),
        'startdate': request.GET.get('startdate')

on the server side.

Try it and let me know. (I’m not a django or python user, so the server-side code I’m not 100% about, but from reading this and this I think I’ve got the idea.)