urls.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:django-open-lecture 作者: DmLitov4 项目源码 文件源码
def check_pattern_startswith_slash(pattern):
    """
    Check that the pattern does not begin with a forward slash.
    """
    regex_pattern = pattern.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('^/'):
        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(
                describe_pattern(pattern)
            ),
            id="urls.W002",
        )
        return [warning]
    else:
        return []
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号