我正在编写调用django.core.urlresolvers.reverse()
生成链接的便捷代码。但是,我似乎无法编写一个简单的URLconf来进行快速测试。
这是我尝试过的:
>>> from django.conf.urls import patterns, url
>>> conf = patterns('', url(r'^foo/$', lambda request: None, name='foo'))
>>> from django.core.urlresolvers import reverse
>>> reverse('foo', conf)
Traceback (most recent call last):
File "<console>", line 1, in <module>
File ".../env/local/lib/python2.7/site-packages/django/core/urlresolvers.py", line 445, in reverse
resolver = get_resolver(urlconf)
File ".../env/local/lib/python2.7/site-packages/django/utils/functional.py", line 27, in wrapper
if mem_args in cache:
TypeError: unhashable type: 'list'
我在 Python 2.7 上使用 Django 1.5。