mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-07-27 08:29:59 +03:00
add checks before make filter kwargs
This commit is contained in:
parent
d74a5bfd18
commit
c25971c754
|
@ -84,29 +84,31 @@ class GenericAPIView(views.APIView):
|
|||
keyword arguments in the url conf.
|
||||
"""
|
||||
queryset = self.filter_queryset(self.get_queryset())
|
||||
|
||||
# Perform the lookup filtering.
|
||||
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
||||
|
||||
assert lookup_url_kwarg in self.kwargs, (
|
||||
'Expected view %s to be called with a URL keyword argument '
|
||||
'named "%s". Fix your URL conf, or set the `.lookup_field` '
|
||||
'attribute on the view correctly.' %
|
||||
(self.__class__.__name__, lookup_url_kwarg)
|
||||
)
|
||||
|
||||
lookup_arg = self.lookup_arg
|
||||
|
||||
assert lookup_arg in self.request.GET, (
|
||||
'Expected view %s to be called with a URL keyword argument '
|
||||
'named "%s". Fix your URL conf, or set the `.lookup_arg` '
|
||||
'attribute on the view correctly.' %
|
||||
(self.__class__.__name__, lookup_arg)
|
||||
)
|
||||
if lookup_arg is None:
|
||||
|
||||
filter_kwargs = {self.lookup_field: self.request.GET[lookup_arg]} \
|
||||
if lookup_arg is not None \
|
||||
else {self.lookup_field: self.kwargs[lookup_url_kwarg]}
|
||||
# Perform the lookup filtering.
|
||||
lookup_url_kwarg = self.lookup_url_kwarg or self.lookup_field
|
||||
|
||||
assert lookup_url_kwarg in self.kwargs, (
|
||||
'Expected view %s to be called with a URL keyword argument '
|
||||
'named "%s". Fix your URL conf, or set the `.lookup_field` '
|
||||
'attribute on the view correctly.' %
|
||||
(self.__class__.__name__, lookup_url_kwarg)
|
||||
)
|
||||
filter_kwargs = {self.lookup_field: self.kwargs[lookup_url_kwarg]}
|
||||
|
||||
else:
|
||||
|
||||
assert lookup_arg in self.request.GET, (
|
||||
'Expected view %s to be called with a URL keyword argument '
|
||||
'named "%s". Fix your URL conf, or set the `.lookup_arg` '
|
||||
'attribute on the view correctly.' %
|
||||
(self.__class__.__name__, lookup_arg)
|
||||
)
|
||||
|
||||
filter_kwargs = {self.lookup_field: self.request.GET[lookup_arg]}
|
||||
|
||||
obj = get_object_or_404(queryset, **filter_kwargs)
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user