How to check if a function returns response object

django, python, response

Solution

You can test if it is an instance of `HttpResponse`, it is the base class for all response types.

from django.http import HttpResponse

def check_func(request):

    res = func()
    if isinstance(res, HttpResponse):
       #do something

Problem

I have a function which calls another function and proceeds on the result of the called function. What I want to do is to check if the function being called returns a `response` object or not and then use it in the existing function. I tried to use `isinstance` but I am not getting what arg to use. ``` def func(request): return HttpResponse('xyz') def check_func(request): res = func() # Here I want to check if res is response object or not # And continue accordingly ``` Do suggest some ways to check .

Original source