Monday, 3 May 2021

Django-cms admin url 404 after language change

I recently started learning Django & Django CMS, and was trying to change the language of my website from English to Dutch, I migrated over my pages using

Page.objects.filter(languages='en').update(languages='nl')
Title.objects.filter(language='en').update(language='nl')
CMSPlugin.objects.filter(language='en').update(language='nl')

In my settings.py I also changed LANGUAGE_CODE to 'nl' and set my languages and CMS languages as follows

LANGUAGES = (
    ## Customize this
    ('nl', 'Nederlands'),
)

CMS_LANGUAGES = {
    ## Customize this
    1: [
        {
            'code': 'nl',
            'name': 'Nederlands',
            'redirect_on_fallback': True,
            'public': True,
            'hide_untranslated': False,
        },
    ],
    'default': {
        'redirect_on_fallback': True,
        'public': True,
        'hide_untranslated': False,
    },
}

This works like a charm for the normal pages, but as soon as I try to open the admin interface I get the following error

Request Method: GET
Request URL:    http://localhost:8000/nl/en/admin/cms/page/?language=en
Raised by:  cms.views.details
Using the URLconf defined in PinManagementSite.urls, Django tried these URL patterns, in this order:

sitemap.xml
nl/ admin/
nl/ ^cms_login/$ [name='cms_login']
nl/ ^cms_wizard/
nl/ ^(?P<slug>[0-9A-Za-z-_.//]+)/$ [name='pages-details-by-slug']
nl/ ^$ [name='pages-root']
^media/(?P<path>.*)$
^static/(?P<path>.*)$
The current path, /nl/en/admin/cms/page/, didn't match any of these.

As far as I can see I configured it all correctly, but when I go to the admin pages it tries to route me through /nl/en instead of just /nl/ and I can't figure out why.

For completeness I'll add my urls.py below

from cms.sitemaps import CMSSitemap
from django.conf import settings
from django.conf.urls.i18n import i18n_patterns
from django.conf.urls.static import static
from django.contrib import admin
from django.contrib.sitemaps.views import sitemap
from django.urls import include, path

admin.autodiscover()

urlpatterns = [
    path("sitemap.xml", sitemap, {"sitemaps": {"cmspages": CMSSitemap}}),
]


urlpatterns += i18n_patterns(
    path("admin/", admin.site.urls),
    path("", include("cms.urls")),
)

# This is only needed when using runserver.
if settings.DEBUG:
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
    urlpatterns += static(settings.STATIC_URL, document_root=settings.STATIC_ROOT)

Versions are djangocms==3.8.0 & Django==3.1.8



from Django-cms admin url 404 after language change

No comments:

Post a Comment