Best practice method for evaluating if a Django request object is (or not) before slicing it up?

Depending on how my script is being executed, I need to know if the variable created at the end is a request object or not before slicing it.

I use:

if type(variable) == models.query.QuerySet:
    do_this

      

the problem with evaluating a variable like this is that now when I slice it it becomes a list which is not what I want because now I cannot call the method .values()

.

Thanks in advance for any solutions :)

+3


source to share


1 answer


You can use:



if isinstance(variable, QuerySet):
    do_this

      

+2


source







All Articles