'list'对象没有属性'get'



我想在views.py中返回数字,但总是得到属性错误。我不想得到什么,我只是想返回一个变量,但它总是显示"对象没有属性"get"。我曾试图改变返回数字字符串和列表,但都得到了这个错误


Traceback (most recent call last):
File "C:UsersAsusAppDataLocalProgramsPythonPython310libsite-packagesdjangocorehandlersexception.py", line 55, in inner
response = get_response(request)
File "C:UsersAsusAppDataLocalProgramsPythonPython310libsite-packagesdjangoutilsdeprecation.py", line 136, in __call__
response = self.process_response(request, response)
File "C:UsersAsusAppDataLocalProgramsPythonPython310libsite-packagesdjangomiddlewareclickjacking.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'

这是我在views.py函数

中的代码
number = 3
return number
谁能帮我解决这个问题?我已经在网上搜索了,但没有找到解决方案!

视图需要返回一个HttpResponse。

from django.http import HttpResponse
def my_view(request):
return HttpResponse('hello')

你还应该分享你的整个视图,而不仅仅是两行。

您是否尝试过打印(type())来检查变量是否真的是您想要的类型?

最新更新