简体   繁体   中英

'list' object has no attribute 'get'

I would like to return number in views.py but always get the attribute error. I am not want to get something, I just want to return a variable, but it always shows " object has no attribute '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

   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.

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?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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