我有一个看起来像这样的网址:
url(r'^client_profile/address/(?P<id>.+)/$', views.ClientProfileAddressView.as_view())
和APIView:
class ClientProfileAddressView(APIView):
renderer_classes = (JSONRenderer,)
permission_classes = (IsAuthenticated,)
def put(self, request):
....
def get(self, request):
....
在put
和get
中,我需要访问id
url kwarg,第一个更新对象,第二个更新它。如何在这些方法中访问url参数?
答案 0 :(得分:7)
这应该有效:
def put(self, request, *args, **kwargs):
id = kwargs.get('id', 'Default Value if not there')
def get(self, request, *args, **kwargs):
id = kwargs.get('id', 'Default Value if not there')