我收到消息“您已注册”,但是当我检入数据库时​​,数据未保存在数据库中。当我重新加载页面时,数据不见了

Fullcalendar无法更新和保存数据。我收到消息“您已注册”,但是当我检入数据库时​​,数据未保存在数据库中。当我重新加载(index.html)页面时,数据消失了。当我重新加载carenda / add_event /时,数据可以保存在数据库中。为了获取日历,我知道我需要写点东西,但是我不知道应该在index.html中的路径“'***”中写些什么。我在互联网上搜索了几天,并试图操纵一些东西,但仍然无法完成。我对Django,Javascript,JSON和Sqlite还是很陌生。请帮我。

index.html

<!DOCTYPE html>
<html>
   <head>
      <link rel="stylesheet" href="{% static 'carenda/css/fullcalendar.min.css' %}"/>
<link rel="stylesheet" href="{% static 'carenda/css/style.css' %}">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
<script type="text/javascript" src="{% static 'carenda/js/moment.min.js' %}"></script>
<script type="text/javascript" src="{% static 'carenda/js/fullcalendar.min.js' %}"></script>
<script type="text/javascript" src="{% static 'carenda/lang/ja.js' %}"></script>
      <script>
         // ページ読み込み時の処理
         $(document).ready(function () {

         // カレンダーの設定
         $('#calendar').fullCalendar({
            height: 550,
            lang: "ja",
            header: {
               left: 'prev,next today',
               center: 'title',
               right: 'month,basicWeek,basicDay'
            },
            timeFormat: 'HH:mm',
            selectable: true,
            selectHelper: true,
            navLinks: true,
            eventSources: [{
               path: '***',
               dataType: 'json',
               async: false,
               type : 'GET',
               error: function() {
                  $('#script-warning').show();
               }
            }],
            select: function(start, end, resource) {
               var title = prompt("title:");
               var eventData;
               if (title) {
                  // nesting json data
                  eventData = {
                     title: title,
                     start: start,
                     end: end,
                  };
                  $('#calendar').fullCalendar('renderEvent', eventData, true);
                  //load json project
                  $.ajax({
                     path: '/carenda/add_event',
                     type: "GET",
                     data: JSON.stringify(eventData),
                     success: function(data) {
                        alert("You have registered!")
                     },
                     error: function(jsonResponse) {
                        alert("cannot insert!")
                     }
                  });
               }
               $('#calendar').fullCalendar('unselect');
               },
               editable: true,
               eventLimit: true,
            });

         });
      </script>
   </head>
   <body>
      <div id='calendar'></div>
   </body>
</html>

models.py

import datetime
from django.db import models
from django.utils import timezone

class Events(models.Model):
    id = models.AutoField(primary_key=True)
    title = models.CharField(max_length=255,null=True,blank=True)
    start = models.DateTimeField(null=True,blank=True)
    end = models.DateTimeField(null=True,blank=True)

    def __str__(self):
        return self.title

views.py

def add_event(request):
     start = request.GET.get("start", None)
     end = request.GET.get("end", None)
     title = request.GET.get("title", None)
     event = Events(name=str(title), start=start, end=end)
     event.save()
     data = {}
     return JsonResponse(data)

urls.py

from django.urls import path
from . import views

app_name = 'carenda'
urlpatterns = [
    path('', views.index, name='index'),
    path('<int:pk>/', views.detail, name='detail'),
    # path('regist/',views.RegistSchedule, name='regist'),
    path('add_event/', views.add_event, name='add_event'),
]
评论