What is the address between request.query_params and self.request.query_params in Python with Django

1

I'm starting with djangorestframework of django-python and I have the following code:

class ProcesoViewSet(ModelPagination, viewsets.ViewSet):

    def list(self, request):
        query = request.query_params
        query1 = self.request.query_params
        log.info(query)
        log.info(query1)

I would like to know what the difference is, I did log the two values this is the result (it's the same)

<QueryDict: {'page': ['1'], 'all': ['false']}>
<QueryDict: {'page': ['1'], 'all': ['false']}>

But I would like to know there are advantages and disadvantages of using one or the other. Thanks.

    
asked by Vitmar Aliaga 07.07.2017 в 07:37
source

1 answer

0

When a page is requested in Django, an object is created HttpRequest that contains information about the request, that is, its attributes and methods.

In your example, this object is in the instance of class ProcesoViewSet and you have access to it from the instance using self.request .

In def list(self, request) there is a parameter called request , but it is only a label . Coincidentally is called request and causally contains the content of the object self.request . But it's just chance. Its name could be req or solicitud or any other and its function would be the same.

Now, both objects can have the same content , but not necessarily they are the same object .

To check if two objects have the same content , use the logical operator == .

query == query1

To check if two variables refer to the same object , use the operator is :

query is query1
    
answered by 07.07.2017 в 16:03