获取完整日历 javascript 点击数据到 django modelform

Getting fullcalendar javascript click data to django modelform

我想点击 Fullcalendar 上的事件,然后打开另一个页面,像这样

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

。 但是如何从 fullcalendar 获取数据呢? 有用于显示日期的函数 dateStr,以及用于在时间线视图中显示资源的 resource.id(全日历)

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

。 我想要的是将 dateStr 和 resource.id 单击的数据带到 django modelform,

此处views.py

@login_required(login_url='login')
def create_book(request):
    booking_forms = BookingForm(initial={
        'resourceId':'xxxx',
        'startdate':'xxxx'
    })

我不确定我应该在 xxxx 上放什么才能通过其他页面上的 url 获得此内容..

谢谢..

在任何网络应用程序中,如果要将数据传递到另一个页面,通常会以某种方式将其添加到 URL。

例如像 /create_book?resourceId=123&startdate=2021-02-18.

所以在你的情况下,我希望是这样的

window.open("{% url 'create-book' %}?resourceId=" + encodeURIComponent(info.resource.id) + "&startdate=" + encodeURIComponent(info.dateStr),"_self");

客户端需要,

@login_required(login_url='login')
def create_book(request):
    booking_forms = BookingForm(initial={
        'resourceId': request.GET.get('resourceId'),
        'startdate': request.GET.get('startdate')
    })

在服务器端。

试试看,然后告诉我。 (我不是 django 或 python 用户,所以我不是 100% 了解服务器端代码,但是通过阅读 this and 我想我明白了。)