python类urls()的实例源码

compat.py 文件源码 项目:sdining 作者: Lurance 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def include(module, namespace=None, app_name=None):
    from django.conf.urls import include
    if django.VERSION < (1,9):
        return include(module, namespace, app_name)
    else:
        return include((module, app_name), namespace)
compat.py 文件源码 项目:graphene-jwt-auth 作者: darwin4031 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def include(module, namespace=None, app_name=None):
    from django.conf.urls import include
    if django.VERSION < (1,9):
        return include(module, namespace, app_name)
    else:
        return include((module, app_name), namespace)
router.py 文件源码 项目:django-binder 作者: CodeYellowBV 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def urls(self):
        urls = []
        for route, view in self.route_views.items():
            name = view.model.__name__ if view.model else route.route
            # List and detail endpoints
            if route.list_endpoint:
                urls.append(django.conf.urls.url(r'^{}/$'.format(route.route), view.as_view(), {'router': self}, name=name))
            if route.detail_endpoint:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/$'.format(route.route), view.as_view(), {'router': self}, name=name))

            # History views
            if view.model and hasattr(view.model, 'Binder') and view.model.Binder.history:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/history/$'.format(route.route), view.as_view(), {'history': 'normal', 'router': self}, name=name))
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/history/debug/$'.format(route.route), view.as_view(), {'history': 'debug', 'router': self}, name=name))

            # File field endpoints
            for ff in view.file_fields:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/{}/$'.format(route.route, ff),
                        view.as_view(), {'file_field': ff, 'router': self}, name='{}.{}'.format(name, ff)))

            # Custom endpoints
            for m in dir(view):
                method = getattr(view, m)
                if hasattr(method, 'detail_route') or hasattr(method, 'list_route'):
                    route_name = method.route_name
                    extra = method.extra_route
                    kwargs = {'method': m, 'router': self}
                    if method.unauthenticated:
                        kwargs['unauthenticated'] = True
                    if hasattr(method, 'detail_route'):
                        urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/{}/{}$'.format(route.route, route_name, extra),
                                view.as_view(), kwargs, name='{}.{}'.format(name, route_name)))
                    if hasattr(method, 'list_route'):
                        urls.append(django.conf.urls.url(r'^{}/{}/{}$'.format(route.route, route_name, extra),
                                view.as_view(), kwargs, name='{}.{}'.format(name, route_name)))

        return urls
router.py 文件源码 项目:django-binder 作者: CodeYellowBV 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def urls(self):
        urls = []
        for route, view in self.route_views.items():
            name = view.model.__name__ if view.model else route.route
            # List and detail endpoints
            if route.list_endpoint:
                urls.append(django.conf.urls.url(r'^{}/$'.format(route.route), view.as_view(), {'router': self}, name=name))
            if route.detail_endpoint:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/$'.format(route.route), view.as_view(), {'router': self}, name=name))

            # History views
            if view.model and hasattr(view.model, 'Binder') and view.model.Binder.history:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/history/$'.format(route.route), view.as_view(), {'history': 'normal', 'router': self}, name=name))
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/history/debug/$'.format(route.route), view.as_view(), {'history': 'debug', 'router': self}, name=name))

            # File field endpoints
            for ff in view.file_fields:
                urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/{}/$'.format(route.route, ff),
                        view.as_view(), {'file_field': ff, 'router': self}, name='{}.{}'.format(name, ff)))

            # Custom endpoints
            for m in dir(view):
                method = getattr(view, m)
                if hasattr(method, 'detail_route') or hasattr(method, 'list_route'):
                    route_name = method.route_name
                    extra = method.extra_route
                    kwargs = {'method': m, 'router': self}
                    if method.unauthenticated:
                        kwargs['unauthenticated'] = True
                    if hasattr(method, 'detail_route'):
                        urls.append(django.conf.urls.url(r'^{}/(?P<pk>[0-9]+)/{}/{}$'.format(route.route, route_name, extra),
                                view.as_view(), kwargs, name='{}.{}'.format(name, route_name)))
                    if hasattr(method, 'list_route'):
                        urls.append(django.conf.urls.url(r'^{}/{}/{}$'.format(route.route, route_name, extra),
                                view.as_view(), kwargs, name='{}.{}'.format(name, route_name)))

        return urls


问题


面经


文章

微信
公众号

扫码关注公众号