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!
CodePudding user response:
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.
CodePudding user response:
Have you tried to print(type()) for checking purposes if the variable is really type that you want?