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


Python routing.NotFound方法代码示例

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


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

示例1: dispatch_url

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def dispatch_url(self, url_string):
        url, url_adapter, query_args = self.parse_url(url_string)

        try:
            endpoint, kwargs = url_adapter.match()
        except NotFound:
            raise NotSupported(url_string)
        except RequestRedirect as e:
            new_url = "{0.new_url}?{1}".format(e, url_encode(query_args))
            return self.dispatch_url(new_url)

        try:
            handler = import_string(endpoint)
            request = Request(url=url, args=query_args)
            return handler(request, **kwargs)
        except RequestRedirect as e:
            return self.dispatch_url(e.new_url) 
开发者ID:dongweiming,项目名称:daenerys,代码行数:19,代码来源:app.py

示例2: get_view_function

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def get_view_function(url, method='GET'):
    adapter = current_app.url_map.bind('localhost')
    try:
        match = adapter.match(url, method=method)
    except RequestRedirect as e:
        # recursively match redirects
        return get_view_function(e.new_url, method)
    except (MethodNotAllowed, NotFound):
        # no match
        return None

    try:
        # return the view function and arguments
        return current_app.view_functions[match[0]], match[1]
    except KeyError:
        # no view is associated with the endpoint
        return None 
开发者ID:honmaple,项目名称:maple-blog,代码行数:19,代码来源:alias.py

示例3: to_python

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def to_python(self, value):
        try:
            return self.model.objects.get_or_404(id=value)
        except NotFound:
            pass
        try:
            quoted = self.quote(value)
            query = db.Q(slug=value) | db.Q(slug=quoted)
            obj = self.model.objects(query).get()
        except (InvalidQueryError, self.model.DoesNotExist):
            # If the model doesn't have a slug or matching slug doesn't exist.
            if self.has_redirected_slug:
                latest = self.model.slug.latest(value)
                if latest:
                    return LazyRedirect(latest)
            return NotFound()
        else:
            if obj.slug != value:
                return LazyRedirect(quoted)
        return obj 
开发者ID:opendatateam,项目名称:udata,代码行数:22,代码来源:routing.py

示例4: lazy_raise_or_redirect

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def lazy_raise_or_redirect():
    '''
    Raise exception lazily to ensure request.endpoint is set
    Also perform redirect if needed
    '''
    if not request.view_args:
        return
    for name, value in request.view_args.items():
        if isinstance(value, NotFound):
            request.routing_exception = value
            break
        elif isinstance(value, LazyRedirect):
            new_args = request.view_args
            new_args[name] = value.arg
            new_url = url_for(request.endpoint, **new_args)
            return redirect(new_url) 
开发者ID:opendatateam,项目名称:udata,代码行数:18,代码来源:routing.py

示例5: test_dispatch

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def test_dispatch(self):
        env = create_environ('/')
        map = r.Map([
            r.Rule('/', endpoint='root'),
            r.Rule('/foo/', endpoint='foo')
        ])
        adapter = map.bind_to_environ(env)

        raise_this = None
        def view_func(endpoint, values):
            if raise_this is not None:
                raise raise_this
            return Response(repr((endpoint, values)))
        dispatch = lambda p, q=False: Response.force_type(adapter.dispatch(view_func, p,
                                                          catch_http_exceptions=q), env)

        assert dispatch('/').data == b"('root', {})"
        assert dispatch('/foo').status_code == 301
        raise_this = r.NotFound()
        self.assert_raises(r.NotFound, lambda: dispatch('/bar'))
        assert dispatch('/bar', True).status_code == 404 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:23,代码来源:routing.py

示例6: test_server_name_casing

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def test_server_name_casing(self):
        m = r.Map([
            r.Rule('/', endpoint='index', subdomain='foo')
        ])

        env = create_environ()
        env['SERVER_NAME'] = env['HTTP_HOST'] = 'FOO.EXAMPLE.COM'
        a = m.bind_to_environ(env, server_name='example.com')
        assert a.match('/') == ('index', {})

        env = create_environ()
        env['SERVER_NAME'] = '127.0.0.1'
        env['SERVER_PORT'] = '5000'
        del env['HTTP_HOST']
        a = m.bind_to_environ(env, server_name='example.com')
        try:
            a.match()
        except r.NotFound:
            pass
        else:
            assert False, 'Expected not found exception' 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:23,代码来源:routing.py

示例7: _does_route_exist

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def _does_route_exist(self, url: str, method: str) -> bool:
        adapter = self.app.url_map.bind('')
        try:
            adapter.match(url, method=method)
        except RequestRedirect as e:
            # recursively match redirects
            return self._does_route_exist(e.new_url, method)
        except (MethodNotAllowed, NotFound):
            # no match
            return False
        return True 
开发者ID:joegasewicz,项目名称:flask-jwt-router,代码行数:13,代码来源:_routing.py

示例8: test_environ_defaults

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def test_environ_defaults(self):
        environ = create_environ("/foo")
        self.assert_strict_equal(environ["PATH_INFO"], '/foo')
        m = r.Map([r.Rule("/foo", endpoint="foo"), r.Rule("/bar", endpoint="bar")])
        a = m.bind_to_environ(environ)
        self.assert_strict_equal(a.match("/foo"), ('foo', {}))
        self.assert_strict_equal(a.match(), ('foo', {}))
        self.assert_strict_equal(a.match("/bar"), ('bar', {}))
        self.assert_raises(r.NotFound, a.match, "/bars") 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:11,代码来源:routing.py

示例9: test_environ_nonascii_pathinfo

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def test_environ_nonascii_pathinfo(self):
        environ = create_environ(u'/лошадь')
        m = r.Map([
            r.Rule(u'/', endpoint='index'),
            r.Rule(u'/лошадь', endpoint='horse')
        ])
        a = m.bind_to_environ(environ)
        self.assert_strict_equal(a.match(u'/'), ('index', {}))
        self.assert_strict_equal(a.match(u'/лошадь'), ('horse', {}))
        self.assert_raises(r.NotFound, a.match, u'/барсук') 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:12,代码来源:routing.py

示例10: test_basic_routing

# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import NotFound [as 别名]
def test_basic_routing(self):
        map = r.Map([
            r.Rule('/', endpoint='index'),
            r.Rule('/foo', endpoint='foo'),
            r.Rule('/bar/', endpoint='bar')
        ])
        adapter = map.bind('example.org', '/')
        assert adapter.match('/') == ('index', {})
        assert adapter.match('/foo') == ('foo', {})
        assert adapter.match('/bar/') == ('bar', {})
        self.assert_raises(r.RequestRedirect, lambda: adapter.match('/bar'))
        self.assert_raises(r.NotFound, lambda: adapter.match('/blub'))

        adapter = map.bind('example.org', '/test')
        try:
            adapter.match('/bar')
        except r.RequestRedirect as e:
            assert e.new_url == 'http://example.org/test/bar/'
        else:
            self.fail('Expected request redirect')

        adapter = map.bind('example.org', '/')
        try:
            adapter.match('/bar')
        except r.RequestRedirect as e:
            assert e.new_url == 'http://example.org/bar/'
        else:
            self.fail('Expected request redirect')

        adapter = map.bind('example.org', '/')
        try:
            adapter.match('/bar', query_args={'aha': 'muhaha'})
        except r.RequestRedirect as e:
            assert e.new_url == 'http://example.org/bar/?aha=muhaha'
        else:
            self.fail('Expected request redirect')

        adapter = map.bind('example.org', '/')
        try:
            adapter.match('/bar', query_args='aha=muhaha')
        except r.RequestRedirect as e:
            assert e.new_url == 'http://example.org/bar/?aha=muhaha'
        else:
            self.fail('Expected request redirect')

        adapter = map.bind_to_environ(create_environ('/bar?foo=bar',
                                                     'http://example.org/'))
        try:
            adapter.match()
        except r.RequestRedirect as e:
            assert e.new_url == 'http://example.org/bar/?foo=bar'
        else:
            self.fail('Expected request redirect') 
开发者ID:GeekTrainer,项目名称:Flask,代码行数:55,代码来源:routing.py


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