【问题标题】:Django Ajax Get method giving 405 (Method Not Allowed) errorDjango Ajax Get 方法给出 405(不允许方法)错误
【发布时间】:2021-02-17 15:42:22
【问题描述】:

$(document).on("click", "#btn_create_card", function () {
  url1 = $(this).attr("data-url");

  $.ajax({
    url: url1,
    type: "GET",
    data: {
      description: "test",
    },
    success: function () {
      console.log("sucess");
      Get_CardView();
    },
  });
});

下面是我的基于类的调用视图

  class CreateCard(View):

      def get(self, request):
          description1 = request.GET.get('description', None)
          print(description1)

          return redirect('/')

但我收到以下错误消息

GET http://127.0.0.1:8000/create_card?description=test 405(方法不允许)

下面是我的网址

path('create_card',  views.CreateCard.as_view(), name='create_card'),

【问题讨论】:

    标签: django ajax


    【解决方案1】:

    试了将近一个小时,才发现是因为改了网址名。我将所有功能和 URL 的“Book”重命名为“Card”。

    似乎 Django 正在从 .pyc 中检索。

    删除 .pyc 文件并重新运行解决。

    【讨论】:

      猜你喜欢
      • 2017-11-13
      • 2020-07-26
      • 1970-01-01
      • 1970-01-01
      • 2019-07-05
      • 2021-09-17
      • 1970-01-01
      • 2020-07-04
      • 2021-12-20
      相关资源
      最近更新 更多