Python django 模块,urls() 实例源码

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

项目:sdining    作者:Lurance    | 项目源码 | 文件源码
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)
项目:graphene-jwt-auth    作者:darwin4031    | 项目源码 | 文件源码
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)
项目:django-binder    作者:CodeYellowBV    | 项目源码 | 文件源码
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
项目:django-binder    作者:CodeYellowBV    | 项目源码 | 文件源码
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