我得到我的生产服务器上的以下错误:的Python NameError:全局名称“任意”没有定义
Traceback (most recent call last):
File "/usr/lib/python2.4/site-packages/django/core/handlers/base.py", line 89, in get_response
response = middleware_method(request)
File "myproject/middleware.py", line 31, in process_request
if not any(m.match(path) for m in EXEMPT_URLS):
NameError: global name 'any' is not defined
服务器正在运行的Python 2.6和发展并没有提出这个错误。有问题的代码是在middleware.py
:
...
if not request.user.is_authenticated():
path = request.path_info.lstrip('/')
if not any(m.match(path) for m in EXEMPT_URLS):
return HttpResponseRedirect(settings.LOGIN_URL)
我应该重写这个any
功能来解决这个问题呢?
从堆栈跟踪中,您的服务器似乎正在运行Python 2.4,它没有'任何'。 – 2012-01-27 17:59:23
oops。哦耶。任何建议如何重写代码与python2.4兼容? – 2012-01-27 18:14:16
@Ned似乎已经给出了很好的答案。尽管我会尽可能考虑升级。下一个版本的Django(1.4)不支持Python 2.4。 – 2012-01-27 19:19:24