我试过用Api的安装调用反向无效。使用shell确定RegexpURLPattern的名称我确定名称是api_v2_top_level但是调用reverse('api_v2_top_level_')不起作用。有什么想法吗?
# How I determined the name of the view.
In [3]: v2_api.urls
Out[3]:
[<RegexURLPattern api_v2_top_level ^(?P<api_name>v2)/$>,
<RegexURLResolver <RegexURLPattern list> (None:None) ^(?P<api_name>v2)/>,
<RegexURLResolver <RegexURLPattern list> (None:None) ^(?P<api_name>v2)/>,
<RegexURLResolver <RegexURLPattern list> (None:None) ^(?P<api_name>v2)/>]
from tastypie.api import Api
v2_api = Api(api_name='v2')
v2_api.register(...)
...
from api.urls import v2_api
In [4]: v2_api.urls[0]
Out[4]: <RegexURLPattern api_v2_top_level ^(?P<api_name>v2)/$>
In [5]: v2_api.urls[0].name
Out[5]: u'api_v2_top_level'
答案 0 :(得分:1)
reverse('api_v2_top_level', kwargs={'api_name': 'v2'})
应该可以解决问题。