简体   繁体   中英

Django rest framework dynamic view class selection

I am looking for a way dynamically selecting (based of feature flag value) a view class for the same endpoint

The problem I'm trying to tackle is having different behaviour (permission, serializer, search fields etc..) for certain feature flag value, and I would like to make the selection in a single point, not for every attribute separately

Is there a way doing so?

One way to do so is to create a common view and in that view, call your actual views on the basis of your flags.

def middle_view(request, *args, **kwargs):
    if flag:
       return actual_view1(request, *args, **kwargs)
    else:
       return actual_view2(request, *args, **kwargs)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM