Django Redirects + FeinCMS - URL переменная

Я использую старый сервер с Python 2.7 и Django 1.11.7 с FeinCMS в качестве CMS. Если я хочу перенаправить любой входящий URL из запроса со смешанным регистром на правильный URL со всеми строчными буквами, как мне это сделать? Есть ли способ отредактировать входящий запрос, и если страница будет найдена, но будет обнаружено, что она не соответствует URL в нижнем регистре, то будет сделано перенаправление на эту страницу? У меня есть оригинальная функция ниже и одна, которую я отредактировал и добился достаточного прогресса, чтобы заставить правильную страницу отображаться, но URL в адресной строке по-прежнему имеет смешанный регистр. Любая помощь будет очень признательна.

Оригинальная функция:

def dispatch(self, request, *args, **kwargs):
    try:
        return super(Handler, self).dispatch(request, *args, **kwargs)
    except Http404 as e:
        if settings.FEINCMS_CMS_404_PAGE is not None:
            logger.info(
                "Http404 raised for '%s', attempting redirect to"
                " FEINCMS_CMS_404_PAGE", args[0])
            try:
                # Fudge environment so that we end up resolving the right
                # page.
                # Note: request.path is used by the page redirect processor
                # to determine if the redirect can be taken, must be == to
                # page url.
                # Also clear out the _feincms_page attribute which caches
                # page lookups (and would just re-raise a 404).
                request.path = request.path_info =\
                    settings.FEINCMS_CMS_404_PAGE
                if hasattr(request, '_feincms_page'):
                    delattr(request, '_feincms_page')
                response = super(Handler, self).dispatch(
                    request, settings.FEINCMS_CMS_404_PAGE, **kwargs)
                # Only set status if we actually have a page. If we get for
                # example a redirect, overwriting would yield a blank page
                if response.status_code == 200:
                    response.status_code = 404
                return response
            except Http404:
                logger.error(
                    "Http404 raised while resolving"
                    " FEINCMS_CMS_404_PAGE=%s",
                    settings.FEINCMS_CMS_404_PAGE)
                raise e
        else:
            raise

Редактируемая функция:

def dispatch(self, request, *args, **kwargs):
    try:
        try:
            thisRequest = request
            theseArgs = args
            theseKwArgs = kwargs
            theseKwArgs[ 'atb_slug' ] = kwargs[ 'atb_slug' ].lower()
            thisRequest.path_info = request.path_info.lower()
        except:
            thisRequest = ''
            theseArgs = []
            theseKwArgs = []
        thisStr = '\n'.join( [ 'PATH1\t' + str( thisRequest.path_info ) , 'REQ\t' + str( thisRequest.__dict__ ) , 'ARGS\t' + str( theseArgs ) , 'KWARGS\t' + str( theseKwArgs ) ] )
        print( thisStr )
        return super(Handler, self).dispatch(thisRequest, *args, **theseKwArgs )
    except Http404 as e:
        if settings.FEINCMS_CMS_404_PAGE is not None:
            logger.info(
                "Http404 raised for '%s', attempting redirect to"
                " FEINCMS_CMS_404_PAGE", args[0])
            try:
                # Fudge environment so that we end up resolving the right
                # page.
                # Note: request.path is used by the page redirect processor
                # to determine if the redirect can be taken, must be == to
                # page url.
                # Also clear out the _feincms_page attribute which caches
                # page lookups (and would just re-raise a 404).
                request.path = request.path_info =\
                    settings.FEINCMS_CMS_404_PAGE
                if hasattr(request, '_feincms_page'):
                    delattr(request, '_feincms_page')
                response = super(Handler, self).dispatch(
                    request, settings.FEINCMS_CMS_404_PAGE, **kwargs)
                # Only set status if we actually have a page. If we get for
                # example a redirect, overwriting would yield a blank page
                if response.status_code == 200:
                    response.status_code = 404
                return response
            except Http404:
                logger.error(
                    "Http404 raised while resolving"
                    " FEINCMS_CMS_404_PAGE=%s",
                    settings.FEINCMS_CMS_404_PAGE)
                raise e
        else:
            raise
Вернуться на верх