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


Python urls.Resolver404方法代码示例

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


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

示例1: process_template_response

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def process_template_response(self, request, response):
        try:
            url = resolve(request.path_info)
        except Resolver404:
            return response
        if not url.app_name == 'admin' and \
                url.url_name not in ['index', 'app_list']:
            # current view is not a django admin index
            # or app_list view, bail out!
            return response

        try:
            app_list = response.context_data['app_list']
        except KeyError:
            # there is no app_list! nothing to reorder
            return response

        self.init_config(request, app_list)
        ordered_app_list = self.get_app_list()
        response.context_data['app_list'] = ordered_app_list
        return response 
开发者ID:mishbahr,项目名称:django-modeladmin-reorder,代码行数:23,代码来源:middleware.py

示例2: resolved

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def resolved(self):
        resolved = None
        path = self.kwargs.get('path', '')
        if path:
            try:
                resolved = resolve('/editor/'+path+'/')
            except Resolver404:
                pass

        if not resolved:
            try:
                resolved = resolve('/editor/'+path)
            except Resolver404:
                pass

        self.request.sub_resolver_match = resolved

        return resolved 
开发者ID:c3nav,项目名称:c3nav,代码行数:20,代码来源:api.py

示例3: get_node_template_name

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def get_node_template_name(node):
    try:
        view = get_view_from_url(node.get_absolute_url())
    except (AttributeError, Resolver404):
        return settings.DJANGOCMS_SPA_VUE_JS_ERROR_404_TEMPLATE
    if view.__module__ == 'cms.views':
        template = node.attr.get('template')
        if template:
            return template
        else:
            try:
                return node.attr.get('cms_page').get_template()
            except:
                return settings.DJANGOCMS_SPA_VUE_JS_ERROR_404_TEMPLATE
    else:
        try:
            return view.template_name
        except AttributeError:
            return settings.DJANGOCMS_SPA_DEFAULT_TEMPLATE 
开发者ID:dreipol,项目名称:djangocms-spa-vue-js,代码行数:21,代码来源:menu_helpers.py

示例4: count_urls

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def count_urls(self, file_obj):
        urls = {}
        non_match = set()
        for url in file_obj:
            url = url.strip()
            try:
                name = resolve(url).url_name
            except Resolver404:
                non_match.add(url)
                continue

            if name in urls:
                urls[name] = urls[name] + 1
            else:
                urls[name] = 1

        return urls, non_match 
开发者ID:Inboxen,项目名称:Inboxen,代码行数:19,代码来源:url_stats.py

示例5: test_nonmatching_urls

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def test_nonmatching_urls(self):
        test_data = (
            ('int', {'-1', 'letters'}),
            ('str', {'', '/'}),
            ('path', {''}),
            ('slug', {'', 'stars*notallowed'}),
            ('uuid', {
                '',
                '9da9369-838e-4750-91a5-f7805cd82839',
                '39da9369-838-4750-91a5-f7805cd82839',
                '39da9369-838e-475-91a5-f7805cd82839',
                '39da9369-838e-4750-91a-f7805cd82839',
                '39da9369-838e-4750-91a5-f7805cd8283',
            }),
        )
        for url_name, url_suffixes in test_data:
            for url_suffix in url_suffixes:
                url = '/%s/%s/' % (url_name, url_suffix)
                with self.subTest(url=url), self.assertRaises(Resolver404):
                    resolve(url) 
开发者ID:nesdis,项目名称:djongo,代码行数:22,代码来源:tests.py

示例6: add_preserved_filters

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def add_preserved_filters(self, context, url, popup=False, to_field=None):
        opts = context.get('opts')
        preserved_filters = context.get('preserved_filters')

        parsed_url = list(urlparse(url))
        parsed_qs = dict(parse_qsl(parsed_url[4]))
        merged_qs = dict()

        if opts and preserved_filters:
            preserved_filters = dict(parse_qsl(preserved_filters))

            match_url = '/%s' % url.partition(get_script_prefix())[2]
            try:
                match = resolve(match_url)
            except Resolver404:
                pass
            else:
                current_url = '%s:%s' % (match.app_name, match.url_name)
                changelist_url = 'admin:%s_changelist' % self.get_base_viewname()
                if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                    preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

            merged_qs.update(preserved_filters)

        if popup:
            from django.contrib.admin.options import IS_POPUP_VAR
            merged_qs[IS_POPUP_VAR] = 1
        if to_field:
            from django.contrib.admin.options import TO_FIELD_VAR
            merged_qs[TO_FIELD_VAR] = to_field

        merged_qs.update(parsed_qs)

        parsed_url[4] = urlencode(merged_qs)
        return urlunparse(parsed_url) 
开发者ID:inueni,项目名称:django-subadmin,代码行数:37,代码来源:__init__.py

示例7: add_preserved_filters

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
    opts = context.get('opts')
    preserved_filters = context.get('preserved_filters')

    parsed_url = list(urlparse(url))
    parsed_qs = dict(parse_qsl(parsed_url[4]))
    merged_qs = {}

    if opts and preserved_filters:
        preserved_filters = dict(parse_qsl(preserved_filters))

        match_url = '/%s' % url.partition(get_script_prefix())[2]
        try:
            match = resolve(match_url)
        except Resolver404:
            pass
        else:
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

        merged_qs.update(preserved_filters)

    if popup:
        from django.contrib.admin.options import IS_POPUP_VAR
        merged_qs[IS_POPUP_VAR] = 1
    if to_field:
        from django.contrib.admin.options import TO_FIELD_VAR
        merged_qs[TO_FIELD_VAR] = to_field

    merged_qs.update(parsed_qs)

    parsed_url[4] = urlencode(merged_qs)
    return urlunparse(parsed_url) 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:37,代码来源:admin_urls.py

示例8: url_resolves

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def url_resolves(url):
    try:
        resolve(urlparse(url).path)
    except Resolver404:
        return False
    return True 
开发者ID:easy-as-python,项目名称:django-webmention,代码行数:8,代码来源:resolution.py

示例9: __call__

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def __call__(self, request):
        try:
            callback, args, kwargs = resolve(request.path_info, getattr(request, 'urlconf', None))
        except Resolver404:
            callback, args, kwargs = None, None, None

        if getattr(callback, 'short_circuit_middleware', False):
            return callback(request, *args, **kwargs)
        return self.get_response(request) 
开发者ID:DMOJ,项目名称:online-judge,代码行数:11,代码来源:middleware.py

示例10: clean

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def clean(self):
        if "checks" in self.errors:
            del self.errors["checks"]
            self.cleaned_data["checks"] = None
        if "user" in self.errors:
            del self.errors["user"]
            self.cleaned_data["user"] = self.request_user
        if self.errors:
            return
        pootle_path = self.cleaned_data.get("path")
        path_keys = ["project_code", "language_code", "dir_path", "filename"]
        try:
            path_kwargs = {
                k: v for k, v in resolve(pootle_path).kwargs.items() if k in path_keys
            }
        except Resolver404:
            raise forms.ValidationError("Unrecognised path")
        self.cleaned_data.update(path_kwargs)
        sort_on = "units"
        if "filter" in self.cleaned_data:
            unit_filter = self.cleaned_data["filter"]
            if unit_filter in ("suggestions", "user-suggestions"):
                sort_on = "suggestions"
            elif unit_filter in ("user-submissions",):
                sort_on = "submissions"
        sort_by_param = self.cleaned_data["sort"]
        self.cleaned_data["sort_by"] = ALLOWED_SORTS[sort_on].get(sort_by_param)
        self.cleaned_data["sort_on"] = sort_on 
开发者ID:evernote,项目名称:zing,代码行数:30,代码来源:forms.py

示例11: add_preserved_filters

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
    opts = context.get('opts')
    preserved_filters = context.get('preserved_filters')

    parsed_url = list(urlparse(url))
    parsed_qs = dict(parse_qsl(parsed_url[4]))
    merged_qs = {}

    if opts and preserved_filters:
        preserved_filters = dict(parse_qsl(preserved_filters))

        match_url = '/%s' % unquote(url).partition(get_script_prefix())[2]
        try:
            match = resolve(match_url)
        except Resolver404:
            pass
        else:
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

        merged_qs.update(preserved_filters)

    if popup:
        from django.contrib.admin.options import IS_POPUP_VAR
        merged_qs[IS_POPUP_VAR] = 1
    if to_field:
        from django.contrib.admin.options import TO_FIELD_VAR
        merged_qs[TO_FIELD_VAR] = to_field

    merged_qs.update(parsed_qs)

    parsed_url[4] = urlencode(merged_qs)
    return urlunparse(parsed_url) 
开发者ID:PacktPublishing,项目名称:Hands-On-Application-Development-with-PyCharm,代码行数:37,代码来源:admin_urls.py

示例12: _is_whitelisted

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def _is_whitelisted(redirect_url):
    if not redirect_url:
        return False

    parsed = urlparse(redirect_url)
    try:
        match = resolve(parsed.path)
    except Resolver404:
        return False

    return match.url_name in NEXT_WHITELIST 
开发者ID:healthchecks,项目名称:healthchecks,代码行数:13,代码来源:views.py

示例13: add_preserved_filters

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def add_preserved_filters(context, url, popup=False, to_field=None):
    opts = context.get('opts')
    preserved_filters = context.get('preserved_filters')

    parsed_url = list(urlparse(url))
    parsed_qs = dict(parse_qsl(parsed_url[4]))
    merged_qs = dict()

    if opts and preserved_filters:
        preserved_filters = dict(parse_qsl(preserved_filters))

        match_url = '/%s' % url.partition(get_script_prefix())[2]
        try:
            match = resolve(match_url)
        except Resolver404:
            pass
        else:
            current_url = '%s:%s' % (match.app_name, match.url_name)
            changelist_url = 'admin:%s_%s_changelist' % (opts.app_label, opts.model_name)
            if changelist_url == current_url and '_changelist_filters' in preserved_filters:
                preserved_filters = dict(parse_qsl(preserved_filters['_changelist_filters']))

        merged_qs.update(preserved_filters)

    if popup:
        from django.contrib.admin.options import IS_POPUP_VAR
        merged_qs[IS_POPUP_VAR] = 1
    if to_field:
        from django.contrib.admin.options import TO_FIELD_VAR
        merged_qs[TO_FIELD_VAR] = to_field

    merged_qs.update(parsed_qs)

    parsed_url[4] = urlencode(merged_qs)
    return urlunparse(parsed_url) 
开发者ID:Yeah-Kun,项目名称:python,代码行数:37,代码来源:admin_urls.py

示例14: _should_log_route

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def _should_log_route(self, request):
        # request.urlconf may be set by middleware or application level code.
        # Use this urlconf if present or default to None.
        # https://docs.djangoproject.com/en/2.1/topics/http/urls/#how-django-processes-a-request
        # https://docs.djangoproject.com/en/2.1/ref/request-response/#attributes-set-by-middleware
        urlconf = getattr(request, 'urlconf', None)

        try:
            route_match = resolve(request.path, urlconf=urlconf)
        except Resolver404:
            return False, None

        method = request.method.lower()
        view = route_match.func
        func = view
        # This is for "django rest framework"
        if hasattr(view, 'cls'):
            if hasattr(view, 'actions'):
                actions = view.actions
                method_name = actions.get(method)
                if method_name:
                    func = getattr(view.cls, view.actions[method], None)
            else:
                func = getattr(view.cls, method, None)
        elif hasattr(view, 'view_class'):
            # This is for django class-based views
            func = getattr(view.view_class, method, None)
        no_logging = getattr(func, NO_LOGGING_ATTR, False)
        no_logging_msg = getattr(func, NO_LOGGING_MSG_ATTR, None)
        return no_logging, no_logging_msg 
开发者ID:Rhumbix,项目名称:django-request-logging,代码行数:32,代码来源:middleware.py

示例15: get_resolver_matches_chain

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import Resolver404 [as 别名]
def get_resolver_matches_chain(request, data=None):
    """Walk the current request URL path up to the top, attempting to resolve along the way
    """
    from django.urls import Resolver404
    from django.urls import resolve
    resolver_matches_chain = []
    path = request.path
    resolver_matches_chain.append((path, request.resolver_match,))
    while path:
        try:
            path = path[:path.rindex('/')]
            resolver_match = resolve(path)
            resolver_matches_chain.append((path, resolver_match))
        except Resolver404:
            # could not resolve without '/'
            path_with_slash = path + '/'
            if request.path != path_with_slash:
                try:
                    resolver_match = resolve(path_with_slash)
                    resolver_matches_chain.append((path_with_slash, resolver_match))
                except Resolver404:
                    pass
        except ValueError:
            # '/' substring not found
            break
    return resolver_matches_chain 
开发者ID:hacktoolkit,项目名称:django-htk,代码行数:28,代码来源:view_helpers.py


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