0

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?

0

1 Answer 1

1

That's because in your image function, you return image(id) which calls the same function, but this time with id instead of a request object.

Try naming the 2 things differently, e.g. you can rename the view function to image_view.

Sign up to request clarification or add additional context in comments.

1 Comment

yes! that was it. I had another function (the one that made the request to the API) and it had exactly the same name, Thank you so much

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.