我想使用slug和id来访问我的资源,以便以下网址都指向相同的资源
http://site.com/api/resource/this-is-the-slug
http://site.com/api/resource/35
我已将以下内容添加到我的资源
prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]
哪个网站的网址工作正常,但不幸的是打破了网址。 我如何让他们两个一起工作?
答案 0 :(得分:1)
同一视图总是可以有2个目标
此外,slu have永远不会有.
和_
prepend_urls(self):
return [
url(r"^(?P<resource_name>%s)/(?P<slug>[\w\d-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
url(r"^(?P<resource_name>%s)/(?P<id>[\d]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"),
]