没有从openlayer 2 -request获取参数到django 1.11

时间:2017-12-15 09:03:45

标签: django python-2.7 openlayers geodjango django-1.11

我正在使用openlayers 2,Python2.7& Django 1.11。对于搜索,我需要将带有openlayers(javascript)参数的请求发送到Django 1.11。 我能够提交请求,但参数没有得到。我的代码是:

使用Javascript:

var params = ''
var opnLyrRequest = new XMLHttpRequest();
params = 'pid=15&ctype=25&stype=50'
opnLyrRequest.open('POST','/test/search/',true); 
opnLyrRequest.onreadystatechange=function(){ 
    if(opnLyrRequest.readyState==4 && opnLyrRequest.status==200){ 
    if(pinGeoJsonFrmt.read(opnLyrRequest.responseText)!=null){  
        dataLoc = pinGeoJsonFrmt.read(opnLyrRequest.responseText);
        if (dataLoc.length > 0) alert("Found !!"); 
        else alert("No Data Found !!"); 
    } 
    }     
} 
opnLyrRequest.send(params); 

处理上述请求的Django代码是:

@csrf_exempt
def searchSubmit(request):
    print request
    print request.method
    print request.POST
    print request.GET
    # print request.POST["pid"] #results in MultiValueDictKeyError: "'pid'"
    ....
    ....

获得这样的输出:

<WSGIRequest: POST '/test/search/'>
POST
<QueryDict: {}>
<QueryDict: {}>

缺少参数!!

0 个答案:

没有答案