當前位置: 首頁>>代碼示例>>Python>>正文


Python conf.urls方法代碼示例

本文整理匯總了Python中django.conf.urls方法的典型用法代碼示例。如果您正苦於以下問題:Python conf.urls方法的具體用法?Python conf.urls怎麽用?Python conf.urls使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在django.conf的用法示例。


在下文中一共展示了conf.urls方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: _check_pattern_startswith_slash

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_pattern_startswith_slash(self):
        """
        Check that the pattern does not begin with a forward slash.
        """
        regex_pattern = self.regex.pattern
        if not settings.APPEND_SLASH:
            # Skip check as it can be useful to start a URL pattern with a slash
            # when APPEND_SLASH=False.
            return []
        if regex_pattern.startswith(('/', '^/', '^\\/')) and not regex_pattern.endswith('/'):
            warning = Warning(
                "Your URL pattern {} has a route beginning with a '/'. Remove this "
                "slash as it is unnecessary. If this pattern is targeted in an "
                "include(), ensure the include() pattern has a trailing '/'.".format(
                    self.describe()
                ),
                id="urls.W002",
            )
            return [warning]
        else:
            return [] 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:23,代碼來源:resolvers.py

示例2: _check_pattern_startswith_slash

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_pattern_startswith_slash(self):
        """
        Check that the pattern does not begin with a forward slash.
        """
        regex_pattern = self.regex.pattern
        if not settings.APPEND_SLASH:
            # Skip check as it can be useful to start a URL pattern with a slash
            # when APPEND_SLASH=False.
            return []
        if (regex_pattern.startswith('/') or regex_pattern.startswith('^/')) and not regex_pattern.endswith('/'):
            warning = Warning(
                "Your URL pattern {} has a regex beginning with a '/'. Remove this "
                "slash as it is unnecessary. If this pattern is targeted in an "
                "include(), ensure the include() pattern has a trailing '/'.".format(
                    self.describe()
                ),
                id="urls.W002",
            )
            return [warning]
        else:
            return [] 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:23,代碼來源:resolvers.py

示例3: resolve_error_handler

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def resolve_error_handler(self, view_type):
        callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
        if not callback:
            # No handler specified in file; use default
            # Lazy import, since django.urls imports this file
            from django.conf import urls
            callback = getattr(urls, 'handler%s' % view_type)
        return get_callable(callback), {} 
開發者ID:lanbing510,項目名稱:GTDWeb,代碼行數:10,代碼來源:urlresolvers.py

示例4: _check_include_trailing_dollar

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_include_trailing_dollar(self):
        regex_pattern = self.regex.pattern
        if regex_pattern.endswith('$') and not regex_pattern.endswith(r'\$'):
            return [Warning(
                "Your URL pattern {} uses include with a route ending with a '$'. "
                "Remove the dollar from the route to avoid problems including "
                "URLs.".format(self.describe()),
                id='urls.W001',
            )]
        else:
            return [] 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:13,代碼來源:resolvers.py

示例5: _route_to_regex

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _route_to_regex(route, is_endpoint=False):
    """
    Convert a path pattern into a regular expression. Return the regular
    expression and a dictionary mapping the capture names to the converters.
    For example, 'foo/<int:pk>' returns '^foo\\/(?P<pk>[0-9]+)'
    and {'pk': <django.urls.converters.IntConverter>}.
    """
    original_route = route
    parts = ['^']
    converters = {}
    while True:
        match = _PATH_PARAMETER_COMPONENT_RE.search(route)
        if not match:
            parts.append(re.escape(route))
            break
        parts.append(re.escape(route[:match.start()]))
        route = route[match.end():]
        parameter = match.group('parameter')
        if not parameter.isidentifier():
            raise ImproperlyConfigured(
                "URL route '%s' uses parameter name %r which isn't a valid "
                "Python identifier." % (original_route, parameter)
            )
        raw_converter = match.group('converter')
        if raw_converter is None:
            # If a converter isn't specified, the default is `str`.
            raw_converter = 'str'
        try:
            converter = get_converter(raw_converter)
        except KeyError as e:
            raise ImproperlyConfigured(
                "URL route '%s' uses invalid converter %s." % (original_route, e)
            )
        converters[parameter] = converter
        parts.append('(?P<' + parameter + '>' + converter.regex + ')')
    if is_endpoint:
        parts.append('$')
    return ''.join(parts), converters 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:40,代碼來源:resolvers.py

示例6: check

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def check(self):
        warnings = self._check_pattern_startswith_slash()
        route = self._route
        if '(?P<' in route or route.startswith('^') or route.endswith('$'):
            warnings.append(Warning(
                "Your URL pattern {} has a route that contains '(?P<', begins "
                "with a '^', or ends with a '$'. This was likely an oversight "
                "when migrating to django.urls.path().".format(self.describe()),
                id='2_0.W001',
            ))
        return warnings 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:13,代碼來源:resolvers.py

示例7: _check_pattern_name

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_pattern_name(self):
        """
        Check that the pattern name does not contain a colon.
        """
        if self.pattern.name is not None and ":" in self.pattern.name:
            warning = Warning(
                "Your URL pattern {} has a name including a ':'. Remove the colon, to "
                "avoid ambiguous namespace references.".format(self.pattern.describe()),
                id="urls.W003",
            )
            return [warning]
        else:
            return [] 
開發者ID:reBiocoder,項目名稱:bioforum,代碼行數:15,代碼來源:resolvers.py

示例8: _check_pattern_name

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_pattern_name(self):
        """
        Check that the pattern name does not contain a colon.
        """
        if self.name is not None and ":" in self.name:
            warning = Warning(
                "Your URL pattern {} has a name including a ':'. Remove the colon, to "
                "avoid ambiguous namespace references.".format(self.describe()),
                id="urls.W003",
            )
            return [warning]
        else:
            return [] 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:15,代碼來源:resolvers.py

示例9: _check_include_trailing_dollar

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _check_include_trailing_dollar(self):
        """
        Check that include is not used with a regex ending with a dollar.
        """
        regex_pattern = self.regex.pattern
        if regex_pattern.endswith('$') and not regex_pattern.endswith(r'\$'):
            warning = Warning(
                "Your URL pattern {} uses include with a regex ending with a '$'. "
                "Remove the dollar from the regex to avoid problems including "
                "URLs.".format(self.describe()),
                id="urls.W001",
            )
            return [warning]
        else:
            return [] 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:17,代碼來源:resolvers.py

示例10: resolve_error_handler

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def resolve_error_handler(self, view_type):
        callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
        if not callback:
            # No handler specified in file; use lazy import, since
            # django.conf.urls imports this file.
            from django.conf import urls
            callback = getattr(urls, 'handler%s' % view_type)
        return get_callable(callback), {} 
開發者ID:Yeah-Kun,項目名稱:python,代碼行數:10,代碼來源:resolvers.py

示例11: _resolve_special

# 需要導入模塊: from django import conf [as 別名]
# 或者: from django.conf import urls [as 別名]
def _resolve_special(self, view_type):
        callback = getattr(self.urlconf_module, 'handler%s' % view_type, None)
        if not callback:
            # No handler specified in file; use default
            # Lazy import, since django.urls imports this file
            from django.conf import urls
            callback = getattr(urls, 'handler%s' % view_type)
        return get_callable(callback), {} 
開發者ID:blackye,項目名稱:luscan-devel,代碼行數:10,代碼來源:urlresolvers.py


注:本文中的django.conf.urls方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。