Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 开发google chrome扩展时Django应用程序中的AJAX调用出现问题_Python_Django_Ajax_Google Chrome Extension_Web Development Server - Fatal编程技术网

Python 开发google chrome扩展时Django应用程序中的AJAX调用出现问题

Python 开发google chrome扩展时Django应用程序中的AJAX调用出现问题,python,django,ajax,google-chrome-extension,web-development-server,Python,Django,Ajax,Google Chrome Extension,Web Development Server,当我试图使用popup.js中的ajax调用将数据发送到本地主机时,我收到一个错误: 找不到/ “获取/情感/?编号=219 HTTP/1.1”404 1714 即使我检查了url,它是正确的并且存在。 这是我的ajax调用的片段: $.ajax({ url:"http://127.0.0.1:8000/sentiment/", dataType:"json", data:{

当我试图使用popup.js中的ajax调用将数据发送到本地主机时,我收到一个错误: 找不到/ “获取/情感/?编号=219 HTTP/1.1”404 1714

即使我检查了url,它是正确的并且存在。 这是我的ajax调用的片段:

 $.ajax({ 
                url:"http://127.0.0.1:8000/sentiment/",
                dataType:"json",
                data:{
                    number:newTotal
                },
                crossDomain:true,
                success:function(json)
                {
                    $('#total').text(json.number)
                }
            }) 
这是django应用程序中我的URL.py文件:

from django.contrib import admin
from django.urls import path,include
from DetectHate import views
from django.urls import path,re_path


urlpatterns = [
    path('admin/', admin.site.urls),
    re_path(r'^sentiment/$', views.sentiment,name="sentiment"),

]
这是我的views.py文件-

import json
from django.http import Http404,HttpResponse
from django.views.decorators.csrf import csrf_exempt


@csrf_exempt
def sentiment(request):
    if request.is_ajax():
        var=request.POST.get('number')+5
        data={}
        data['number']=var+5
        return HttpResponse(json.dumps(data),content_type='application/json')
    else:
        raise Http404

好啊我只需要删除if request.is_ajax条件,它就工作了。我认为url有问题,但404只是因为其他部分才出现的。错误在条件中。确定。我只需要删除if request.is_ajax条件,它就工作了。我认为url有问题,但404只是因为其他部分才出现的。错误在条件中。