[Django]-Django i18n_patterns without trailing slash

0👍

I ended up creating a middleware that does the following:

from django.shortcuts import redirect
from django.utils import translation

def add_i18npatterns_trailing_slash(get_response):
    def middleware(request):
        response = get_response(request)
        if response.status_code == 404:
            language_code = translation.get_language()
            if request.path.endswith(language_code):
                return redirect(f'{request.path}/')
        return response
    return middleware
👤Natim

Leave a comment