python 3.x - django rest framework and multiple routers -


i have application api created drf. in use drf-router route url's. want add route list-view parameters (so @list_route won't work) viewsets, not others.

so wanted define 2 routers:

user_router = routers.simplerouter() admin_router = routers.simplerouter() 

i want route added one of them:

search_route = route(     url='^{prefix}/search/(?p<field>\w+)/(?p<value>\w+){trailing_slash}$',     mapping={         'get': 'search',     },     name='{basename}-search',     initkwargs={} )  admin_router.routes.append(search_route) 

but end search_route added both routers, , coupled viewsets register in routers individually.

ipython> user_router.routes ...  route(url='^{prefix}/search/(?p<field>\\w+)/(?p<method>\\w+)/(?p<keyword>\\w+){trailing_slash}$', mapping={'get': 'search'}, name='{basename}-search', initkwargs={'suffix': 'search'}), ... 

why this??? missing basic here. how can add route() routers not others, can split api-urls in "user" , "admin" each own methods.

allright, figured out. simplerouter class in django rest framework defines routes in class, , doesn't bind values in __init__ phase. simplerouter.routes list().

since lists mutable, instances of simplerouter point @ same route-list when creating simplerouter instances. when appended route admin_router.routes, updated user_router.routes....

the way overcome define seperate router classes overrride router-list.

class adminrouter(simplerouter):     routes = [ ... list of route()'s ... ]   class userrouter(simplerouter):     routes = [ ... other list of route()'s ...]   admin_router = adminrouter() user_router = userrouter() 

Comments

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -