utils.py 文件源码

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

项目:django-redirect-urls 作者: pmac 项目源码 文件源码
def no_redirect(pattern, locale_prefix=True, re_flags=None):
    """
    Return a url matcher that will stop the redirect middleware and force
    Django to continue with regular URL matching. For use when you have a URL pattern
    you want to serve, and a broad catch-all pattern you want to redirect.
    :param pattern: regex URL patter that will definitely not redirect.
    :param locale_prefix: prepend the locale matching pattern.
    :param re_flags: a string of any of the characters: "iLmsux". Will modify the `pattern` regex
        based on the documented meaning of the flags (see python re module docs).
    :return:
    """
    if locale_prefix:
        pattern = pattern.lstrip('^/')
        pattern = LOCALE_RE + pattern

    if re_flags:
        pattern = '(?{})'.format(re_flags) + pattern

    def _view(request, *args, **kwargs):
        return None

    return url(pattern, _view)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号