我得到我的生產服務器上的以下錯誤:的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