将Django视图返回数据放入响应数据

I have a function based view and it has many checks in it and returns data based on check results. So I don't want to wrap my data into Response object every time manually. Is there a way to put function return value into OK response data automatically in Django Rest Framework? For example to have a valid view like this:

@api_view(['GET'])
def pre_reg_countries(request):
    if some_condition:
        return data_1  # instead of returning Response(data=data_1)
    else:
        if another condition:
            return data_2
        else:
            return []

附言这个想法来自Java Spring框架。

评论