当前位置: 首页>>代码示例>>Python>>正文


Python django.urls方法代码示例

本文整理汇总了Python中django.urls方法的典型用法代码示例。如果您正苦于以下问题:Python django.urls方法的具体用法?Python django.urls怎么用?Python django.urls使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在django的用法示例。


在下文中一共展示了django.urls方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_simple

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_simple(self, request_factory):
        from django.urls import resolve
        request = request_factory.get('/admin/')
        request.resolver_match = resolve('/admin/')

        openapi_request = DjangoOpenAPIRequest(request)

        path = {}
        query = {}
        headers = {
            'Cookie': '',
        }
        cookies = {}
        assert openapi_request.parameters == RequestParameters(
            path=path,
            query=query,
            header=headers,
            cookie=cookies,
        )
        assert openapi_request.method == request.method.lower()
        assert openapi_request.full_url_pattern == \
            request._current_scheme_host + request.path
        assert openapi_request.body == request.body
        assert openapi_request.mimetype == request.content_type 
开发者ID:p1c2u,项目名称:openapi-core,代码行数:26,代码来源:test_django.py

示例2: get_url_patterns

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def get_url_patterns(self, ):
        prefix = hasattr(self, 'prefix') and self.prefix or ''

        url_patterns = [
            url(r'^'+prefix+'$', self.perms['list'](self.get_list_class_view().as_view()), name=self.list_url_name, ),
            url(r'^'+prefix+'create/$', self.perms['create'](self.get_create_class_view().as_view()), name=self.create_url_name ),
            url(r'^'+prefix+'detail/(?P<pk>\d+)$', self.perms['detail'](self.get_detail_class_view().as_view()), name=self.detail_url_name ),
            url(r'^'+prefix+'update/(?P<pk>\d+)$', self.perms['update'](self.get_update_class_view().as_view()), name=self.update_url_name ),
            url(r'^'+prefix+'delete/(?P<pk>\d+)$', self.perms['delete'](self.get_delete_class_view().as_view()), name=self.delete_url_name ),
        ]

        if django.VERSION >= (1, 8, 0):
            return url_patterns
        else:
            from django.conf.urls import patterns
            return patterns('', *url_patterns) 
开发者ID:spapas,项目名称:django-generic-scaffold,代码行数:18,代码来源:views.py

示例3: test_legacy_resolver_newstyle_django20_urlconf

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_legacy_resolver_newstyle_django20_urlconf():
    from django.urls import path

    url_conf = (path("api/v2/<int:project_id>/store/", lambda x: ""),)
    resolver = RavenResolver()
    result = resolver.resolve("/api/v2/1234/store/", url_conf)
    assert result == "/api/v2/{project_id}/store/" 
开发者ID:getsentry,项目名称:sentry-python,代码行数:9,代码来源:test_transactions.py

示例4: test_useful_error_messages

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_useful_error_messages(self):
        """ Tests that the system gracefully handles a developer error
            (eg exception in get_absolute_url).
        """
        if django.VERSION < (2, 0):
            from django.core.urlresolvers import NoReverseMatch
        else:
            from django.urls import NoReverseMatch
        with self.assertRaises(NoReverseMatch):
            self.page.type = "a type with spaces!"  # this causes get_absolute_url() to fail
            self.page.save()
            self.fail("No exception raised on developer error.") 
开发者ID:whyflyru,项目名称:django-seo,代码行数:14,代码来源:tests.py

示例5: django_settings

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def django_settings(self):
        import django
        from django.conf import settings
        from django.contrib import admin
        from django.urls import path

        if settings.configured:
            return

        settings.configure(
            ALLOWED_HOSTS=[
                'testserver',
            ],
            INSTALLED_APPS=[
                'django.contrib.admin',
                'django.contrib.auth',
                'django.contrib.contenttypes',
                'django.contrib.messages',
                'django.contrib.sessions',
            ],
            MIDDLEWARE=[
                'django.contrib.sessions.middleware.SessionMiddleware',
                'django.contrib.auth.middleware.AuthenticationMiddleware',
                'django.contrib.messages.middleware.MessageMiddleware',
            ]
        )
        django.setup()
        settings.ROOT_URLCONF = (
            path('admin/', admin.site.urls),
        ) 
开发者ID:p1c2u,项目名称:openapi-core,代码行数:32,代码来源:test_django.py

示例6: test_url_rule

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_url_rule(self, request_factory):
        from django.urls import resolve
        request = request_factory.get('/admin/auth/group/1/')
        request.resolver_match = resolve('/admin/auth/group/1/')

        openapi_request = DjangoOpenAPIRequest(request)

        path = {
            'object_id': '1',
        }
        query = {}
        headers = {
            'Cookie': '',
        }
        cookies = {}
        assert openapi_request.parameters == RequestParameters(
            path=path,
            query=query,
            header=headers,
            cookie=cookies,
        )
        assert openapi_request.method == request.method.lower()
        assert openapi_request.full_url_pattern == \
            request._current_scheme_host + "/admin/auth/group/{object_id}/"
        assert openapi_request.body == request.body
        assert openapi_request.mimetype == request.content_type 
开发者ID:p1c2u,项目名称:openapi-core,代码行数:28,代码来源:test_django.py

示例7: test_response_validator_path_pattern

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_response_validator_path_pattern(
            self, django_spec, request_factory, response_factory):
        from django.urls import resolve
        validator = ResponseValidator(django_spec)
        request = request_factory.get('/admin/auth/group/1/')
        request.resolver_match = resolve('/admin/auth/group/1/')
        openapi_request = DjangoOpenAPIRequest(request)
        response = response_factory(b('Some item'))
        openapi_response = DjangoOpenAPIResponse(response)
        result = validator.validate(openapi_request, openapi_response)
        assert not result.errors 
开发者ID:p1c2u,项目名称:openapi-core,代码行数:13,代码来源:test_django.py

示例8: test_request_validator_path_pattern

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_request_validator_path_pattern(
            self, django_spec, request_factory):
        from django.urls import resolve
        validator = RequestValidator(django_spec)
        request = request_factory.get('/admin/auth/group/1/')
        request.resolver_match = resolve('/admin/auth/group/1/')
        openapi_request = DjangoOpenAPIRequest(request)
        result = validator.validate(openapi_request)
        assert not result.errors 
开发者ID:p1c2u,项目名称:openapi-core,代码行数:11,代码来源:test_django.py

示例9: get_admin_interface_languages

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def get_admin_interface_languages(context):
    if not settings.USE_I18N:
        # i18n disabled
        return None
    if len(settings.LANGUAGES) < 2:
        # less than 2 languages
        return None
    try:
        set_language_url = reverse('set_language')
    except NoReverseMatch:
        # ImproperlyConfigured - must include i18n urls:
        # urlpatterns += [url(r'^i18n/', include('django.conf.urls.i18n')),]
        return None
    request = context.get('request', None)
    if not request:
        return None
    full_path = request.get_full_path()
    admin_nolang_url = re.sub(r'^\/([\w]{2})([\-\_]{1}[\w]{2})?\/', '/', full_path)
    if admin_nolang_url == full_path:
        # ImproperlyConfigured - must include admin urls using i18n_patterns:
        # from django.conf.urls.i18n import i18n_patterns
        # urlpatterns += i18n_patterns(url(r'^admin/', admin.site.urls))
        return None
    langs_data = []
    default_lang_code = settings.LANGUAGE_CODE
    current_lang_code = translation.get_language() or default_lang_code
    for language in settings.LANGUAGES:
        lang_code = language[0].lower()
        lang_name = language[1].title()
        lang_data = {
            'code': lang_code,
            'name': lang_name,
            'default': lang_code == default_lang_code,
            'active': lang_code == current_lang_code,
            'activation_url': '{}?next=/{}{}'.format(
                set_language_url, lang_code, admin_nolang_url)
        }
        langs_data.append(lang_data)
    return langs_data 
开发者ID:fabiocaccamo,项目名称:django-admin-interface,代码行数:41,代码来源:admin_interface_tags.py

示例10: is_route_pattern

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def is_route_pattern(urlpattern):
    if hasattr(urlpattern, 'pattern'):
        # Django 2.0
        from django.urls.resolvers import RoutePattern
        return isinstance(urlpattern.pattern, RoutePattern)
    else:
        # Django < 2.0
        return False 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:10,代码来源:compat.py

示例11: make_url_resolver

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def make_url_resolver(regex, urlpatterns):
    try:
        # Django 2.0
        from django.urls.resolvers import RegexPattern
        return URLResolver(RegexPattern(regex), urlpatterns)

    except ImportError:
        # Django < 2.0
        return URLResolver(regex, urlpatterns) 
开发者ID:BeanWei,项目名称:Dailyfresh-B2C,代码行数:11,代码来源:compat.py

示例12: test_bad_re_catastrophic_usage_django

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_bad_re_catastrophic_usage_django(self):
        python_node = self.get_ast_node(
            """
            import django

            django.core.validators.RegexValidator('(a+)+b')
            django.urls.re_path('(a+)+b')
            """
        )

        linter = dlint.linters.BadReCatastrophicUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=4,
                col_offset=0,
                message=dlint.linters.BadReCatastrophicUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=5,
                col_offset=0,
                message=dlint.linters.BadReCatastrophicUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:30,代码来源:test_bad_re_catastrophic_use.py

示例13: test_bad_re_catastrophic_usage_from_import_django

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def test_bad_re_catastrophic_usage_from_import_django(self):
        python_node = self.get_ast_node(
            """
            from django.core.validators import RegexValidator
            from django.urls import re_path

            RegexValidator('(a+)+b')
            re_path('(a+)+b')
            """
        )

        linter = dlint.linters.BadReCatastrophicUseLinter()
        linter.visit(python_node)

        result = linter.get_results()
        expected = [
            dlint.linters.base.Flake8Result(
                lineno=5,
                col_offset=0,
                message=dlint.linters.BadReCatastrophicUseLinter._error_tmpl
            ),
            dlint.linters.base.Flake8Result(
                lineno=6,
                col_offset=0,
                message=dlint.linters.BadReCatastrophicUseLinter._error_tmpl
            ),
        ]

        assert result == expected 
开发者ID:duo-labs,项目名称:dlint,代码行数:31,代码来源:test_bad_re_catastrophic_use.py

示例14: urlpatterns

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def urlpatterns(*urls):
    if django.VERSION < (1, 10):
        from django.conf.urls import patterns

        return patterns("", *urls)

    return list(urls) 
开发者ID:5monkeys,项目名称:django-bananas,代码行数:9,代码来源:__init__.py

示例15: urlpatterns

# 需要导入模块: import django [as 别名]
# 或者: from django import urls [as 别名]
def urlpatterns():
    """
    URL's as a lazy object because they touch admin.site.urls and that isn't
    ready until django.setup() has been called
    """
    if django.VERSION >= (2, 0):
        from django.urls import include, path

        patterns = [
            path("", home),
            path("hello/", hello),
            path("crash/", crash),
            path("return-error/", return_error),
            path("cbv/", CbvView.as_view()),
            path("sql/", sql),
            path("sql-kwargs/", sql_kwargs),
            path("sql-type-errors/", sql_type_errors),
            path("template/", template),
            path("template-response/", template_response),
            path("admin/", admin.site.urls),
            path("drf-router/", include(drf_router.urls)),
        ]
        if tastypie_api:
            patterns.append(path("tastypie-api/", include(tastypie_api.urls)))
        return patterns

    else:
        from django.conf.urls import include, url

        patterns = [
            url(r"^$", home),
            url(r"^hello/$", hello),
            url(r"^crash/$", crash),
            url(r"^return-error/$", return_error),
            url(r"^cbv/$", CbvView.as_view()),
            url(r"^sql/$", sql),
            url(r"^sql-kwargs/$", sql_kwargs),
            url(r"^sql-type-errors/$", sql_type_errors),
            url(r"^template/$", template),
            url(r"^template-response/$", template_response),
            url(r"^admin/", admin.site.urls),
            url(r"^drf-router/", include(drf_router.urls)),
        ]
        if tastypie_api:
            patterns.append(url(r"^tastypie-api/", include(tastypie_api.urls)))
        return patterns 
开发者ID:scoutapp,项目名称:scout_apm_python,代码行数:48,代码来源:django_app.py


注:本文中的django.urls方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。