Python rest_framework.routers 模块,SimpleRouter() 实例源码

我们从Python开源项目中,提取了以下2个代码示例,用于说明如何使用rest_framework.routers.SimpleRouter()

项目:django-api-toolkit    作者:hulygun    | 项目源码 | 文件源码
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
项目:py2swagger    作者:Arello-Mobile    | 项目源码 | 文件源码
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()