gpt4 book ai didi

python - 为什么我得到 "AttributeError: ' unicode' object has no attribute 'user' "on some specified url only only?

转载 作者:太空狗 更新时间:2023-10-30 02:00:19 25 4
gpt4 key购买 nike

我从第一天起就在我的项目中使用@login_required 装饰器,它工作正常,但出于某种原因,我开始“AttributeError:'unicode' 对象在某些特定的 url(以及过去有效的 url)上没有属性'user'"。

示例:我是网站,已登录,然后单击链接,出现此错误,该错误通常与未安装 SessionMiddleware 这一事实有关。但就我而言,有一个是因为我登录了该站点并且我所在的页面也有一个@login_required。

有什么想法吗?

url 定义为:(r'^accept/(?P<token>[a-zA-Z0-9_-]+)?$', 'accept'),方法为:@login_required
def accept(request,token): ...

回溯:

Traceback (most recent call last):
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/core/servers/basehttp.py", line 674, in __call__
return self.application(environ, start_response)
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/core/handlers/wsgi.py", line 241, in __call__
response = self.get_response(request)
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/core/handlers/base.py", line 141, in get_response
return self.handle_uncaught_exception(request, resolver, sys.exc_info())
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/core/handlers/base.py", line 165, in handle_uncaught_exception
return debug.technical_500_response(request, *exc_info)
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/core/handlers/base.py", line 100, in get_response
response = callback(request, *callback_args, **callback_kwargs)
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/contrib/auth/decorators.py", line 25, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/Users/macbook/dev/pycharm-projects/proj/match/views.py", line 33, in accept
return __process(token,callback)
File "/Users/macbook/virtualenv/proj/lib/python2.6/site-packages/django/contrib/auth/decorators.py", line 24, in _wrapped_view
if test_func(request.user):
AttributeError: 'unicode' object has no attribute 'user'`

最佳答案

装饰器位于私有(private)方法上,该方法没有将请求作为参数。我删除了那个装饰器(因为重构和缺乏测试 [bad me] 而留在那儿)。

问题已解决。

关于python - 为什么我得到 "AttributeError: ' unicode' object has no attribute 'user' "on some specified url only only?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4900003/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com