我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用rest_framework.routers.SimpleRouter()。
def register_models(self): from .models import RestModel from rest_framework.routers import SimpleRouter router = SimpleRouter() for app_name in settings.PROJECT_APPS: models = dict(apps.all_models[app_name]).values() for model in models: if RestModel in model.__bases__: router.register(*model._rest_endpoint()) return router
def setUp(self): RedefineViewSet.as_view = viewset_as_view_decorator(RedefineViewSet.as_view) router = routers.SimpleRouter() router.register(r'd-view$', RedefineViewSet, base_name='test_base_name') self.url_patterns = router.urls url_parser = UrlParser() self.apis = url_parser.get_apis(url_patterns=self.url_patterns) self.api_introspector = ApiIntrospector(self.apis) self.api_introspector.inspect()