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


Python urls.resolve方法代码示例

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


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

示例1: process_template_response

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [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: test_action_code_confusion

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def test_action_code_confusion(self):
        # Obtain change password code
        self.assertResetPasswordSuccessResponse(self.reset_password(self.email))
        reset_password_link = self.assertResetPasswordEmail(self.email)
        path = urlparse(reset_password_link).path
        reset_password_code = resolve(path).kwargs.get('code')

        # Obtain deletion code
        self.assertDeleteAccountSuccessResponse(self.delete_account(self.email, self.password))
        delete_link = self.assertDeleteAccountEmail(self.email)
        path = urlparse(delete_link).path
        deletion_code = resolve(path).kwargs.get('code')

        # Swap codes
        self.assertNotEqual(reset_password_code, deletion_code)
        delete_link = delete_link.replace(deletion_code, reset_password_code)
        reset_password_link = reset_password_link.replace(reset_password_code, deletion_code)

        # Make sure links don't work
        self.assertVerificationFailureInvalidCodeResponse(self.client.verify(delete_link))
        self.assertVerificationFailureInvalidCodeResponse(self.client.verify(reset_password_link,
                                                                             data={'new_password': 'dummy'})) 
开发者ID:desec-io,项目名称:desec-stack,代码行数:24,代码来源:test_user_management.py

示例3: parse_self_atom

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def parse_self_atom(feed_url):
    """
    解析本站提供的 RSS 源
    :param feed_url:
    :return: 解析结果,成功字典;失败 None
    """

    feed_path = urllib.parse.urlparse(feed_url).path

    try:
        name = resolve(feed_path).kwargs.get('name')
    except:
        name = None

    if name:
        try:
            Site.objects.get(name=name, status='active')
            return {"name": name}
        except:
            logger.warning(f'订阅源不存在:`{feed_url}')

    return None 
开发者ID:richshaw2015,项目名称:oh-my-rss,代码行数:24,代码来源:atom.py

示例4: get_admin_site

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def get_admin_site(current_app):
    """
    Method tries to get actual admin.site class, if any custom admin sites
    were used. Couldn't find any other references to actual class other than
    in func_closer dict in index() func returned by resolver.
    """
    try:
        resolver_match = resolve(reverse('%s:index' % current_app))
        # Django 1.9 exposes AdminSite instance directly on view function
        if hasattr(resolver_match.func, 'admin_site'):
            return resolver_match.func.admin_site

        for func_closure in resolver_match.func.__closure__:
            if isinstance(func_closure.cell_contents, AdminSite):
                return func_closure.cell_contents
    except:
        pass
    return admin.site 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:20,代码来源:suit_menu.py

示例5: process_url

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def process_url(self, url, app=None):
        """
        Try to guess if it is absolute url or named
        """
        if url is None:
            return ''

        if not url or '/' in url:
            return url

        # Model link, ex: 'auth.user'
        if '.' in url:
            url_parts = url.split('.')
            model = self.make_model_from_native(url_parts[1], url_parts[0])
            if model:
                if app:
                    app['model'] = model
                return model['url']

        # Try to resolve as named url, ex: 'admin:index'
        try:
            return reverse(url)
        except:
            return url 
开发者ID:ra-systems,项目名称:django-ra-erp,代码行数:26,代码来源:suit_menu.py

示例6: get_admin_site

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def get_admin_site(current_app):
    """
    Method tries to get actual admin.site class, if any custom admin sites
    were used. Couldn't find any other references to actual class other than
    in func_closer dict in index() func returned by resolver.
    """
    try:
        resolver_match = resolve(reverse('%s:index' % current_app))
        # Django 1.9 exposes AdminSite instance directly on view function
        if hasattr(resolver_match.func, 'admin_site'):
            return resolver_match.func.admin_site

        for func_closure in resolver_match.func.__closure__:
            if isinstance(func_closure.cell_contents, AdminSite):
                return func_closure.cell_contents
    except:
        pass
    from django.contrib import admin
    return admin.site 
开发者ID:wuyue92tree,项目名称:django-adminlte-ui,代码行数:21,代码来源:adminlte_menu.py

示例7: test_simple

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [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

示例8: authorize

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def authorize(self, request):
        if not settings.MAINTENANCE_ENABLE:
            # Not to use this env
            return True

        current_url = resolve(request.path_info).url_name

        if current_url in [
            'home', 'login', 'logout', 'maintenance', 'list',
            'detail', 'bill_download', 'pmt_download'
        ]:
            if request.user.is_authenticated:
                if request.user.is_superuser:
                    return True
                else:
                    #  Logout all non superusers (local admins)
                    logout(request)
                    return True
            else:
                return True
        else:
            return False 
开发者ID:betagouv,项目名称:mrs,代码行数:24,代码来源:middleware.py

示例9: process_request

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def process_request(self, request):
        if not settings.ST_PRIVATE_FORUM:
            return

        if request.user.is_authenticated:
            return

        resolver_match = resolve(request.path)

        if not resolver_match.namespaces:
            return

        if resolver_match.namespaces[0] != 'spirit':
            return

        full_namespace = ':'.join(resolver_match.namespaces)

        if full_namespace == 'spirit:user:auth':
            return

        return redirect_to_login(
            next=request.get_full_path(),
            login_url=settings.LOGIN_URL) 
开发者ID:nitely,项目名称:Spirit,代码行数:25,代码来源:middleware.py

示例10: transform_model

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def transform_model(
    request: http.HttpRequest,
    workflow: Optional[models.Workflow] = None,
) -> http.HttpResponse:
    """Show the table of models.

    :param request: HTTP Request
    :param workflow: Object to apply the models.
    :return:
    """
    url_name = resolve(request.path).url_name
    is_model = url_name == 'model'

    table_err = None
    if request.user.is_superuser:
        table_err = models.Plugin.objects.filter(is_model=None)

    return render(
        request,
        'dataops/transform_model.html',
        {
            'table': services.create_model_table(request, workflow, is_model),
            'is_model': is_model,
            'table_err': table_err}) 
开发者ID:abelardopardo,项目名称:ontask_b,代码行数:26,代码来源:transform.py

示例11: test_resolve_account_URLs

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def test_resolve_account_URLs(self):
        resolver = resolve('/accounts/login/')
        self.assertEqual(resolver.view_name, 'account_login')
        resolver = resolve('/accounts/signup/')
        self.assertEqual(resolver.view_name, 'account_signup')
        resolver = resolve('/accounts/logout/')
        self.assertEqual(resolver.view_name, 'account_logout')
        resolver = resolve('/accounts/password/reset/')
        self.assertEqual(resolver.view_name, 'account_reset_password') 
开发者ID:openwisp,项目名称:openwisp-users,代码行数:11,代码来源:tests.py

示例12: canonical_url

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def canonical_url(context, entry=None):
    if entry and resolve(context.request.path_info).url_name == 'wagtail_serve':
        return context.request.build_absolute_uri(entry_url(context, entry, entry.blog_page))
    return context.request.build_absolute_uri() 
开发者ID:APSL,项目名称:puput,代码行数:6,代码来源:puput_tags.py

示例13: add_preserved_filters

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [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

示例14: view_func

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def view_func(self, *args, **kwargs):
        if self._view_func is None:
            match = resolve(self.view_url)
            self._view_func = match.func
        return self._view_func(*args, **kwargs) 
开发者ID:apragacz,项目名称:django-rest-registration,代码行数:7,代码来源:views.py

示例15: link_to_view

# 需要导入模块: from django import urls [as 别名]
# 或者: from django.urls import resolve [as 别名]
def link_to_view(self, url):
        url = url.replace('http://testserver/', '/')
        url = url.replace('http://localhost:8000/', '/')
        return resolve(url).func 
开发者ID:sfu-fas,项目名称:coursys,代码行数:6,代码来源:tests.py


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