Reputation: 3
i'm creating a rest api with django 1.8 and djangorestframework and also creating the client side using extjs 6.2, i'm getting this error when i send an ajax request to the server 'WSGIRequest' object has no attribute 'query_params' my view is recieving a WSGIRequest object instead of the Request object, what bothers me is that i'm getting this error now when creating any view, all other(previously created) work fine, here are my MIDDLEWARE_CLASSES
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.auth.middleware.SessionAuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
'django.middleware.security.SecurityMiddleware',
'corsheaders.middleware.CorsMiddleware',)
and here are both the django view and extjs ajax request
django view
api_view(["GET"])
def testView(request):
print(request.__class__)
req = json.loads(request.query_params['array'])# here it gives the error
lolo = {"response":"data"}
return JsonResponse(data, safe=False)
extjs Ajax request
var data = 'insert':{idlineapresupuesto_id:1, idusuario_id:1, nombre:"aaaaaa"}
Ext.Ajax.request({
url :"http://127.0.0.1:8000/editarConcGastosView/?format=json",
method: 'GET',
dataType: 'json',
params: {array: Ext.JSON.encode(data)},
success : function(response){
var jsonResp = Ext.util.JSON.decode(response.responseText);//Guarda en jsonResp la respuesta de la peticion
Upvotes: 0
Views: 2215
Reputation: 599630
You haven't used the decorator properly: you need an @
.
@api_view(["GET"])
def testView(request):
Upvotes: 0