i have been working with django to make an interactive web page. But when i try to make a Http request to a django view. It throws that error, even though i have the exact same code above and that works just fine. Here is my Python code:
def test(request):
default = {"Error" : "Could not make request"}
name = request.GET.get('showname')
token = getToken()
showJs = searchShowId(name, token)
if showJs.get('Error'):
try:
token = refreshToken(token)
showJs = searchShowId(name, token)
return JsonResponse(showJs)
except KeyError as error:
token = login()
showJs = searchShowId(name, token)
return JsonResponse(showJs)
else:
return JsonResponse(showJs)
def image(request):
default = {"Error" : "Could not make request"}
id = request.GET.get('id')
return JsonResponse(image(id))
this is the full error:
Traceback:
File "C:\Users\\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\exception.py" in inner
35. response = get_response(request)
File "C:\Users\\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
128. response = self.process_exception_by_middleware(e, request)
File "C:\Users\\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\handlers\base.py" in _get_response
126. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "E:\Documentos\Programming\DjangoProjects\mediaD\mediaDe\views.py" in image
33. return JsonResponse(image(id))
File "E:\Documentos\Programming\DjangoProjects\mediaD\mediaDe\views.py" in image
32. id = request.GET.get('id')
Exception Type: AttributeError at /image/
Exception Value: 'str' object has no attribute 'GET'
Javascript Code:
function search() {
console.log('Function Called')
var showName = document.getElementById('showName');
console.log(showName.value);
var name = stringToPost(showName.value);
$.ajax({
type: "GET",
url: "/request/",
data: {
showname: showName.value
},
success: function (dato) {
dato = dato['data'];
for (var i = 0; i < dato.length; i++) {
$.ajax({
type: "GET",
url: "/image/",
data: {
id : dato[i]['id']
},
success: function (datax) {
console.log(datax);
},
});
}
},
});
Like i already said, the test function works perfectly, but the image one doesnt. What could it be?