Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.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
Javascript Django-Ajax调用正常,但未调用python方法_Javascript_Jquery_Python_Ajax_Django - Fatal编程技术网

Javascript Django-Ajax调用正常,但未调用python方法

Javascript Django-Ajax调用正常,但未调用python方法,javascript,jquery,python,ajax,django,Javascript,Jquery,Python,Ajax,Django,我试图在views.py中对django方法进行Ajax POST调用,我调用的Ajax是ok的: 问题是在views.py中没有调用我的方法get_elem,当我在该方法上使用调试器时,进程不会在断点处停止。(使用Pycharm) 我的ajax调用是: 函数调用元素(元素id,元素类型){ } 如您所见,我已经从cookie中获得了csrf令牌。views.py中的方法是: def get_elem(request): if request.method == "POST"

我试图在
views.py
中对django方法进行Ajax POST调用,我调用的Ajax是ok的:

问题是在
views.py
中没有调用我的方法
get_elem
,当我在该方法上使用调试器时,进程不会在断点处停止。(使用Pycharm)

我的ajax调用是:

函数调用元素(元素id,元素类型){

}

如您所见,我已经从cookie中获得了csrf令牌。
views.py
中的方法是:

def get_elem(request):
if request.method == "POST":
    if request.POST.get('elem_id') and request.POST.get('elem_type'):
        elem_id = request.POST.get('elem_id')
        elem_type = request.POST.get('elem_type')
        if elem_type == 'GR' or elem_type == 'GRC':
            elem = Groupe.objects.get(elem_id)
            json.dumps(elem.__dict__)
else:
    elem = {"error":"error..."}

return JsonResponse(elem)
url(r'^test/get_elem/$', views.get_elem, name='get_elem')
编辑
url.py
中的url是:

def get_elem(request):
if request.method == "POST":
    if request.POST.get('elem_id') and request.POST.get('elem_type'):
        elem_id = request.POST.get('elem_id')
        elem_type = request.POST.get('elem_type')
        if elem_type == 'GR' or elem_type == 'GRC':
            elem = Groupe.objects.get(elem_id)
            json.dumps(elem.__dict__)
else:
    elem = {"error":"error..."}

return JsonResponse(elem)
url(r'^test/get_elem/$', views.get_elem, name='get_elem')
但是,我没有返回JSON中的元素,而是得到了进行ajax调用的页面的HTML代码

我之前在这段代码中已经做了一个ajax调用,没有问题,我不知道为什么这次我不能访问这个方法


显示你的URL模式,
URL.py
for
get\u elem
view.elem=Groupe.objects.get(elem\u id)-“Groupe”拼写正确吗?是的,我的型号是
Groupe
(我是法国人)。但是这个方法甚至没有被调用,我想。。。断点没有停止在AJAX中,您的URL是
get_elem/
,但在
URL.py
中,模式是
test/get_elem/
,请尝试使用标记,这样您就不必硬编码URL模式,例如
URL:“{%URL'get_elem%}”
您的视图中有
if request.method==“get”:
类型:'POST',
在您的javascript中?