[英]django-tastypie REST update or delete resource with username
Hi there i am using django tastypie and i can update (PUT) a resource if i provide an id like this : 嗨,我正在使用django tastypie,如果我提供这样的ID,我可以更新(PUT)资源:
http://mysite.com:8000/api/v1/user/1/ http://mysite.com:8000/api/v1/user/1/
But my question is, can i do an update without the id (pk) but with a username instead? 但是我的问题是,我可以不使用ID(pk)而是使用用户名来进行更新吗? And if yes, how can i do that? 如果是的话,我该怎么做? It would be something like this : 就像这样:
http://mysite.com:8000/api/v1/user/username/ http://mysite.com:8000/api/v1/user/username/
This is described in tastypie cookbook 美味食谱中对此进行了描述
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"),
]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.