當前位置: 首頁>>代碼示例>>Python>>正文


Python routers.DefaultRouter方法代碼示例

本文整理匯總了Python中rest_framework.routers.DefaultRouter方法的典型用法代碼示例。如果您正苦於以下問題:Python routers.DefaultRouter方法的具體用法?Python routers.DefaultRouter怎麽用?Python routers.DefaultRouter使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在rest_framework.routers的用法示例。


在下文中一共展示了routers.DefaultRouter方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: get_router

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def get_router():
    router = routers.DefaultRouter()
    router.register(r'contenttypes', ContentTypeViewSet, 'contenttype')
    router.register(r'groups', GroupViewSet, 'group')
    router.register(r'users', UserViewSet, 'user')
    router.register(r'permissions', PermissionViewSet, 'permission')
    router.register(r'releases', ReleaseViewSet, 'release')
    router.register(r'sections', SectionViewSet, 'section')
    router.register(r'packages', PackageViewSet, 'package')
    router.register(r'versions', VersionViewSet, 'version')
    router.register(r'builds', BuildViewSet, 'build')
    router.register(r'device_types', DeviceTypeViewSet, 'device_type')
    router.register(r'os_versions', OSVersionViewSet, 'os_version')
    router.register(r'settings', SettingViewSet, 'setting')
    router.register(r'galleries', GalleryViewSet, 'gallery')
    router.register(r'photos', PhotoViewSet, 'photo')
    router.register(r'comments', CommentViewSet, 'comment')
    router.register(r'sites', SiteViewSet, 'site')
    return router 
開發者ID:82Flex,項目名稱:DCRM,代碼行數:21,代碼來源:api.py

示例2: get_urls

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def get_urls(self):
        router = DefaultRouter()
        view_sets = []
        for model, view_set in self._registry.items():
            if view_set.queryset is None:
                view_set.queryset = model.objects.all()
            if view_set.serializer_class is None:
                serializer_class = type("%sModelSerializer" % model.__name__, (ModelSerializer,), {
                    "Meta": type("Meta", (object,), {
                        "model": model,
                        "fields": "__all__"
                    }),
                })
                view_set.serializer_class = serializer_class

            view_sets.append(view_set)
            router.register(self.get_model_url(model), view_set, self.get_model_basename(model))

        return router.urls + self._url_patterns 
開發者ID:amirasaran,項目名稱:django-restful-admin,代碼行數:21,代碼來源:admin.py

示例3: test_format_api_patterns_url_import_with_routers

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def test_format_api_patterns_url_import_with_routers(self):

        class MockApiViewSet(ModelViewSet):
            serializer_class = CommentSerializer
            model = User
            queryset = User.objects.all()

        class AnotherMockApiViewSet(ModelViewSet):
            serializer_class = CommentSerializer
            model = User
            queryset = User.objects.all()

        router = DefaultRouter()
        router.register(r'other_views', MockApiViewSet, base_name='test_base_name')
        router.register(r'more_views', AnotherMockApiViewSet, base_name='test_base_name')

        urls_app = patterns('', url(r'^', include(router.urls)))
        urls = patterns(
            '',
            url(r'api/', include(urls_app)),
            url(r'test/', include(urls_app))
        )
        apis = self.urlparser.get_apis(urls)

        self.assertEqual(
            4, sum(api['path'].find('api') != -1 for api in apis))
        self.assertEqual(
            4, sum(api['path'].find('test') != -1 for api in apis)) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:30,代碼來源:test_urlparser.py

示例4: test_exclude_router_api_root

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def test_exclude_router_api_root(self):
        class MyViewSet(ModelViewSet):
            serializer_class = CommentSerializer
            queryset = User.objects.all()
            model = User

        router = DefaultRouter()
        router.register('test', MyViewSet, base_name='test_base_name')

        urls_created = len(router.urls)

        apis = self.urlparser.get_apis(router.urls)

        self.assertEqual(4, urls_created - len(apis)) 
開發者ID:Arello-Mobile,項目名稱:py2swagger,代碼行數:16,代碼來源:test_urlparser.py

示例5: setUp

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def setUp(self):
        self.router = DefaultRouter()
        self.router.register(r'locations', LocationViewSet)
        self.view = LocationViewSet.as_view({'get': 'list'}) 
開發者ID:bkg,項目名稱:django-spillway,代碼行數:6,代碼來源:test_viewsets.py

示例6: router_urls

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def router_urls():
    router = routers.DefaultRouter(trailing_slash=False)
    router.register(r'articles', ArticleViewSet)
    router.register(r'categories', CategoryViewSet)
    router.register(r'trained-codings', TrainedCodingViewSet)

    return router.urls 
開發者ID:chicago-justice-project,項目名稱:chicago-justice,代碼行數:9,代碼來源:api_views.py

示例7: get_api_root_view

# 需要導入模塊: from rest_framework import routers [as 別名]
# 或者: from rest_framework.routers import DefaultRouter [as 別名]
def get_api_root_view(self, api_urls: List[str] = None) -> Dict:
        """Gets api root view."""
        self.logger.debug("Getting api root view")
        api_root_dict: Dict = OrderedDict()
        list_name = self.routes[0].name
        for prefix, viewset, basename in self.registry:
            api_root_dict[prefix] = list_name.format(basename=basename)

        class APIRootView(views.APIView):
            """ The default basic root view for DefaultRouter """

            _ignore_model_permissions = True
            schema = None  # exclude from schema
            api_root_dict: Dict = {}

            def get(self, request: Request, *args: Any, **kwargs: Any) -> Response:
                # Return a plain {"name": "hyperlink"} response.
                response: Dict = OrderedDict()
                namespace = request.resolver_match.namespace
                for key, url_name in self.api_root_dict.items():
                    if namespace:
                        url_name = namespace + ":" + url_name
                    try:
                        response[key] = reverse(
                            url_name,
                            args=args,
                            kwargs=kwargs,
                            request=request,
                            format=kwargs.get("format", None),
                        )
                    except NoReverseMatch:
                        # Don't bail out if eg. no list routes exist, only detail routes.
                        continue

                # Add APIView endpoints
                endpoints = ["recipe/stop", "recipe/{uuid}/start/"]
                base = response["state"].split("api", 1)[0] + "api/"
                for endpoint in endpoints:
                    response[endpoint] = base + endpoint

                return Response(response, 200)

        return APIRootView.as_view(api_root_dict=api_root_dict) 
開發者ID:OpenAgricultureFoundation,項目名稱:openag-device-software,代碼行數:45,代碼來源:router.py


注:本文中的rest_framework.routers.DefaultRouter方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。