ajax发送请求的代码如下:

django框架的代码如下(关键是引入红框的库文件):

参考链接:

  官网:https://docs.djangoproject.com/en/dev/ref/csrf/#ajax