Question

Im using i18n_patterns for my multilingual django site and I want to create an intropage with logo and animation + language chooser. But if I enter my site, it autoredirects me from www.mysite.com => www.mysite.com/en/ ... How can I do it? Here is my urls.py

urlpatterns = i18n_patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
    url(r'^', include('cms.urls')),
)
Was it helpful?

Solution

To prevent the automatic redirect from "/" to "/en/", you have to include a non-i18n pattern in addition to your i18n intro page URL. Otherwise Django will simply take the auto-detected language and check on the i18n patterns.

from django.conf.urls import patterns

urlpatterns = patterns('',
    (r'^$', 'cms.views.your_view')
)

urlpatterns += i18n_patterns('',
    url(r'^admin/', include(admin.site.urls)),
    url(r'^sitemap\.xml$', 'django.contrib.sitemaps.views.sitemap', {'sitemaps': {'cmspages': CMSSitemap}}),
    url(r'^', include('cms.urls')),
)

The non-i18n pattern must point to your intro page view. Don't forget to add the "+" in front of "i18n_patterns". Example and proof it works ;-) Pixabay.com

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top