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


Python exceptions.ViewDoesNotExist方法代码示例

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


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

示例1: extract_views_from_urlpatterns

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def extract_views_from_urlpatterns(urlpatterns, base='', namespace=None):
    """
    Return a list of views from a list of urlpatterns.

    Each object in the returned list is a two-tuple: (view_func, regex)
    """
    views = []
    for p in urlpatterns:
        if hasattr(p, 'url_patterns'):
            try:
                patterns = p.url_patterns
            except ImportError:
                continue
            views.extend(extract_views_from_urlpatterns(
                patterns,
                base + p.regex.pattern,
                (namespace or []) + (p.namespace and [p.namespace] or [])
            ))
        elif hasattr(p, 'callback'):
            try:
                views.append((p.callback, base + p.regex.pattern,
                              namespace, p.name))
            except ViewDoesNotExist:
                continue
        else:
            raise TypeError(_("%s does not appear to be a urlpattern object") % p)
    return views 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:29,代码来源:views.py

示例2: get_callable

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def get_callable(lookup_view, can_fail=False):
    """
    Convert a string version of a function name to the callable object.

    If the lookup_view is not an import path, it is assumed to be a URL pattern
    label and the original string is returned.

    If can_fail is True, lookup_view might be a URL pattern label, so errors
    during the import fail and the string is returned.
    """
    if not callable(lookup_view):
        mod_name, func_name = get_mod_func(lookup_view)
        if func_name == '':
            return lookup_view

        try:
            mod = import_module(mod_name)
        except ImportError:
            parentmod, submod = get_mod_func(mod_name)
            if (not can_fail and submod != '' and
                    not module_has_submodule(import_module(parentmod), submod)):
                raise ViewDoesNotExist(
                    "Could not import %s. Parent module %s does not exist." %
                    (lookup_view, mod_name))
            if not can_fail:
                raise
        else:
            try:
                lookup_view = getattr(mod, func_name)
                if not callable(lookup_view):
                    raise ViewDoesNotExist(
                        "Could not import %s.%s. View is not callable." %
                        (mod_name, func_name))
            except AttributeError:
                if not can_fail:
                    raise ViewDoesNotExist(
                        "Could not import %s. View does not exist in module %s." %
                        (lookup_view, mod_name))
    return lookup_view 
开发者ID:blackye,项目名称:luscan-devel,代码行数:41,代码来源:urlresolvers.py

示例3: test_exceptions

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def test_exceptions(self):
        # A missing view (identified by an AttributeError) should raise
        # ViewDoesNotExist, ...
        with self.assertRaisesMessage(ViewDoesNotExist, "View does not exist in"):
            get_callable('urlpatterns_reverse.views.i_should_not_exist')
        # ... but if the AttributeError is caused by something else don't
        # swallow it.
        with self.assertRaises(AttributeError):
            get_callable('urlpatterns_reverse.views_broken.i_am_broken') 
开发者ID:nesdis,项目名称:djongo,代码行数:11,代码来源:tests.py

示例4: test_view_does_not_exist

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def test_view_does_not_exist(self):
        msg = "View does not exist in module urlpatterns_reverse.views."
        with self.assertRaisesMessage(ViewDoesNotExist, msg):
            get_callable('urlpatterns_reverse.views.i_should_not_exist') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例5: test_non_string_value

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def test_non_string_value(self):
        msg = "'1' is not a callable or a dot-notation path"
        with self.assertRaisesMessage(ViewDoesNotExist, msg):
            get_callable(1) 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例6: test_parent_module_does_not_exist

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def test_parent_module_does_not_exist(self):
        msg = 'Parent module urlpatterns_reverse.foo does not exist.'
        with self.assertRaisesMessage(ViewDoesNotExist, msg):
            get_callable('urlpatterns_reverse.foo.bar') 
开发者ID:nesdis,项目名称:djongo,代码行数:6,代码来源:tests.py

示例7: test_not_callable

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def test_not_callable(self):
        msg = (
            "Could not import 'urlpatterns_reverse.tests.resolve_test_data'. "
            "View is not callable."
        )
        with self.assertRaisesMessage(ViewDoesNotExist, msg):
            get_callable('urlpatterns_reverse.tests.resolve_test_data') 
开发者ID:nesdis,项目名称:djongo,代码行数:9,代码来源:tests.py

示例8: get_resource_uri_template

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def get_resource_uri_template(self):
    """
    URI template processor.
    See http://bitworking.org/projects/URI-Templates/
    """

    def _convert(template, params=[]):
        """URI template converter"""
        paths = template % dict([p, "{%s}" % p] for p in params)
        return "%s%s" % (get_script_prefix(), paths)

    try:
        resource_uri = self.handler.resource_uri()
        components = [None, [], {}]

        for i, value in enumerate(resource_uri):
            components[i] = value
        lookup_view, args, kwargs = components
        try:
            lookup_view = get_callable(lookup_view)
        except (ImportError, ViewDoesNotExist):
            # Emulate can_fail=True from earlier django versions.
            pass

        possibilities = get_resolver(None).reverse_dict.getlist(lookup_view)
        # The monkey patch is right here: we need to cope with 'possibilities'
        # being a list of tuples with 2 or 3 elements.
        for possibility_data in possibilities:
            possibility = possibility_data[0]
            for result, params in possibility:
                if args:
                    if len(args) != len(params):
                        continue
                    return _convert(result, params)
                else:
                    if set(kwargs.keys()) != set(params):
                        continue
                    return _convert(result, params)
    except Exception:
        return None 
开发者ID:maas,项目名称:maas,代码行数:42,代码来源:__init__.py

示例9: get_callable

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def get_callable(lookup_view, can_fail=False):
    """
    Return a callable corresponding to lookup_view. This function is used
    by both resolve() and reverse(), so can_fail allows the caller to choose
    between returning the input as is and raising an exception when the input
    string can't be interpreted as an import path.

    If lookup_view is already a callable, return it.
    If lookup_view is a string import path that can be resolved to a callable,
      import that callable and return it.
    If lookup_view is some other kind of string and can_fail is True, the string
      is returned as is. If can_fail is False, an exception is raised (either
      ImportError or ViewDoesNotExist).
    """
    if callable(lookup_view):
        return lookup_view

    mod_name, func_name = get_mod_func(lookup_view)
    if not func_name:  # No '.' in lookup_view
        if can_fail:
            return lookup_view
        else:
            raise ImportError(
                "Could not import '%s'. The path must be fully qualified." %
                lookup_view)

    try:
        mod = import_module(mod_name)
    except ImportError:
        if can_fail:
            return lookup_view
        else:
            parentmod, submod = get_mod_func(mod_name)
            if submod and not module_has_submodule(import_module(parentmod), submod):
                raise ViewDoesNotExist(
                    "Could not import '%s'. Parent module %s does not exist." %
                    (lookup_view, mod_name))
            else:
                raise
    else:
        try:
            view_func = getattr(mod, func_name)
        except AttributeError:
            if can_fail:
                return lookup_view
            else:
                raise ViewDoesNotExist(
                    "Could not import '%s'. View does not exist in module %s." %
                    (lookup_view, mod_name))
        else:
            if not callable(view_func):
                # For backwards compatibility this is raised regardless of can_fail
                raise ViewDoesNotExist(
                    "Could not import '%s.%s'. View is not callable." %
                    (mod_name, func_name))

            return view_func 
开发者ID:lanbing510,项目名称:GTDWeb,代码行数:59,代码来源:urlresolvers.py

示例10: get_callable

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def get_callable(lookup_view):
    """
    Return a callable corresponding to lookup_view.
    * If lookup_view is already a callable, return it.
    * If lookup_view is a string import path that can be resolved to a callable,
      import that callable and return it, otherwise raise an exception
      (ImportError or ViewDoesNotExist).
    """
    if callable(lookup_view):
        return lookup_view

    if not isinstance(lookup_view, str):
        raise ViewDoesNotExist("'%s' is not a callable or a dot-notation path" % lookup_view)

    mod_name, func_name = get_mod_func(lookup_view)
    if not func_name:  # No '.' in lookup_view
        raise ImportError("Could not import '%s'. The path must be fully qualified." % lookup_view)

    try:
        mod = import_module(mod_name)
    except ImportError:
        parentmod, submod = get_mod_func(mod_name)
        if submod and not module_has_submodule(import_module(parentmod), submod):
            raise ViewDoesNotExist(
                "Could not import '%s'. Parent module %s does not exist." %
                (lookup_view, mod_name)
            )
        else:
            raise
    else:
        try:
            view_func = getattr(mod, func_name)
        except AttributeError:
            raise ViewDoesNotExist(
                "Could not import '%s'. View does not exist in module %s." %
                (lookup_view, mod_name)
            )
        else:
            if not callable(view_func):
                raise ViewDoesNotExist(
                    "Could not import '%s.%s'. View is not callable." %
                    (mod_name, func_name)
                )
            return view_func 
开发者ID:reBiocoder,项目名称:bioforum,代码行数:46,代码来源:utils.py

示例11: get_callable

# 需要导入模块: from django.core import exceptions [as 别名]
# 或者: from django.core.exceptions import ViewDoesNotExist [as 别名]
def get_callable(lookup_view):
    """
    Return a callable corresponding to lookup_view.
    * If lookup_view is already a callable, return it.
    * If lookup_view is a string import path that can be resolved to a callable,
      import that callable and return it, otherwise raise an exception
      (ImportError or ViewDoesNotExist).
    """
    if callable(lookup_view):
        return lookup_view

    if not isinstance(lookup_view, six.string_types):
        raise ViewDoesNotExist("'%s' is not a callable or a dot-notation path" % lookup_view)

    mod_name, func_name = get_mod_func(lookup_view)
    if not func_name:  # No '.' in lookup_view
        raise ImportError("Could not import '%s'. The path must be fully qualified." % lookup_view)

    try:
        mod = import_module(mod_name)
    except ImportError:
        parentmod, submod = get_mod_func(mod_name)
        if submod and not module_has_submodule(import_module(parentmod), submod):
            raise ViewDoesNotExist(
                "Could not import '%s'. Parent module %s does not exist." %
                (lookup_view, mod_name)
            )
        else:
            raise
    else:
        try:
            view_func = getattr(mod, func_name)
        except AttributeError:
            raise ViewDoesNotExist(
                "Could not import '%s'. View does not exist in module %s." %
                (lookup_view, mod_name)
            )
        else:
            if not callable(view_func):
                raise ViewDoesNotExist(
                    "Could not import '%s.%s'. View is not callable." %
                    (mod_name, func_name)
                )
            return view_func 
开发者ID:Yeah-Kun,项目名称:python,代码行数:46,代码来源:utils.py


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