简体   繁体   English

'list' object 没有属性 'get'

[英]'list' object has no attribute 'get'

I would like to return number in views.py but always get the attribute error.我想在 views.py 中返回数字,但总是得到属性错误。 I am not want to get something, I just want to return a variable, but it always shows " object has no attribute 'get'".我不想得到什么,我只想返回一个变量,但它总是显示“object 没有属性‘get’”。 I had tried to change return the number to string and list, but all got this error我曾尝试将返回数字更改为字符串和列表,但都出现此错误


Traceback (most recent call last):
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
    response = get_response(request)
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\django\utils\deprecation.py", line 136, in __call__
    response = self.process_response(request, response)
  File "C:\Users\Asus\AppData\Local\Programs\Python\Python310\lib\site-packages\django\middleware\clickjacking.py", line 27, in process_response
    if response.get("X-Frame-Options") is not None:

Exception Type: AttributeError at /scan-port/
Exception Value: 'int' object has no attribute 'get'

This is my code in views.py function这是我在 views.py 中的代码 function

   number = 3

   return number

Can anyone help me to solve this.谁能帮我解决这个问题。 I had searched online but no solution found!我在网上搜索过,但没有找到解决方案!

A view needs to return a HttpResponse.视图需要返回一个 HttpResponse。

from django.http import HttpResponse

def my_view(request):
    return HttpResponse('hello')

You should also share your whole view instead of just two lines of it.您还应该分享您的整个观点,而不仅仅是其中的两行。

Have you tried to print(type()) for checking purposes if the variable is really type that you want?您是否尝试过 print(type()) 以检查变量是否确实是您想要的类型?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM