Adding a folder to your root Django application site url

If you want to have your Django app in a domain folder like this

Here you have the code to place in file :

from django.conf import settings
from django.urls.resolvers import LocalePrefixPattern
from django.utils.translation import get_language

from django.views.generic.base import RedirectView
APPLICATION_PREFIX = "myfoldername"

def new_language_prefix(self):
    language_code = get_language() or settings.LANGUAGE_CODE
    return '%s/%s/' % (APPLICATION_PREFIX, language_code)

LocalePrefixPattern.language_prefix = property(new_language_prefix)

trans_real.language_code_prefix_re = re.compile(r'^/myfoldername/(\w+([@-]\w+)?)(/|$)')

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s