Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
嗨,我正在使用 django sweetpie,如果我提供这样的 id,我可以更新(PUT)资源:
http://mysite.com:8000/api/v1/user/1/
但我的问题是,我可以在没有 id (pk) 而是使用用户名的情况下进行更新吗?如果是,我该怎么做?它会是这样的:
http://mysite.com:8000/api/v1/user/username/
这在美味的食谱中有描述
class UserResource(ModelResource): class Meta: queryset = User.objects.all() def prepend_urls(self): return [ url(r"^(?P<resource_name>%s)/(?P<username>[\w\d_.-]+)/$" % self._meta.resource_name, self.wrap_view('dispatch_detail'), name="api_dispatch_detail"), ]