Python ';str';对象没有属性';获取';请求使用django脚本时

Python ';str';对象没有属性';获取';请求使用django脚本时,python,django,request,Python,Django,Request,我一直在与django合作制作一个交互式网页。但是当我尝试向django视图发出Http请求时。它抛出了那个错误,尽管我有上面完全相同的代码,而且效果很好。以下是我的Python代码: def test(request): default = {"Error" : "Could not make request"} name = request.GET.get('showname') token = getToken() showJs = searchShow

我一直在与django合作制作一个交互式网页。但是当我尝试向django视图发出Http请求时。它抛出了那个错误,尽管我有上面完全相同的代码,而且效果很好。以下是我的Python代码:

  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))
这是全部错误:

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代码:

 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);
                  },
              });

          }
      },
    });
函数搜索(){
log('调用函数')
var showName=document.getElementById('showName');
console.log(showName.value);
var name=stringToPost(showName.value);
$.ajax({
键入:“获取”,
url:“/request/”,
数据:{
showname:showname.value
},
成功:功能(dato){
dato=dato[‘数据’];
对于(变量i=0;i

正如我已经说过的,test函数工作得很好,但是image one没有。这可能是什么?

这是因为在
image
函数中,您
返回image(id)
,它调用相同的函数,但这次使用
id
而不是
request
对象


尝试以不同的方式命名这两件事,例如,您可以将视图函数重命名为
image\u view

是的!就是这样。我有另一个函数(向API发出请求的函数),它的名称完全相同,非常感谢