1

Using wagtail localize I am getting a weird URL structure:

http://127.0.0.1:8000/en/ [ home ] as expected, when going to http://127.0.0.1:8000.

However, if I try to go to http://127.0.0.1:8000/cn/ suddenly the English locale is appended in front somehow. Resulting in http://127.0.0.1:8000/en/cn/ or http://127.0.0.1:8000/en/cn/about/

When I try to correct the URL to the expected http://127.0.0.1:8000/cn/about/ 'en' gets appended in front again for no obvious reason and the page cannot be found. The same happens when I click "live view" in admin.

Error message

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/en/cn/
Raised by:  wagtail.views.serve
Using the URLconf defined in website.urls, Django tried these URL patterns, in this order:

en/ django-admin/
en/ admin/
en/ documents/
en/ search/ \[name='search'\]
en/ \_util/authenticate_with_password/\<int:page_view_restriction_id\>/\<int:page_id\>/ \[name='wagtailcore_authenticate_with_password'\]
en/ \_util/login/ \[name='wagtailcore_login'\]
en/ ^((?:\[\\w-\]+/)\*)$ \[name='wagtail_serve'\]
The current path, en/cn/, matched the last one.

urls.py


#This is as per the documentation.

from django.conf import settings
from django.urls import include, path
from django.contrib import admin
from django.conf.urls.i18n import i18n_patterns

from wagtail.admin import urls as wagtailadmin_urls
from wagtail import urls as wagtail_urls
from wagtail.documents import urls as wagtaildocs_urls

from search import views as search_views

urlpatterns = \[
path("django-admin/", admin.site.urls),
path("admin/", include(wagtailadmin_urls)),
path("documents/", include(wagtaildocs_urls)),
\]

urlpatterns += i18n_patterns(
path('search/', search_views.search, name='search'),
path("", include(wagtail_urls)),
prefix_default_language=True,
)

if settings.DEBUG:
from django.conf.urls.static import static
from django.contrib.staticfiles.urls import staticfiles_urlpatterns

    # Serve static and media files from development server
    urlpatterns += staticfiles_urlpatterns()
    urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

base.py

# Application definition
INSTALLED_APPS = \[
"home",
"menus",
"resources",
"courses",
"contact",
"schedule",
"search",

    "wagtail_localize",
    "wagtail_localize.locales",
    
    "wagtail.contrib.forms",
    "wagtail.contrib.redirects",
    "wagtail.embeds",
    "wagtail.sites",
    "wagtail.users",
    "wagtail.snippets",
    "wagtail.documents",
    "wagtail.images",
    "wagtail.search",
    "wagtail.admin",
    "wagtail",
    
    "modelcluster",
    "taggit",
    
    "django.contrib.admin",
    "django.contrib.auth",
    "django.contrib.contenttypes",
    "django.contrib.sessions",
    "django.contrib.messages",
    "django.contrib.staticfiles",
    "django_extensions",

\]

MIDDLEWARE = \[
"django.contrib.sessions.middleware.SessionMiddleware",
"django.middleware.common.CommonMiddleware",
"django.middleware.csrf.CsrfViewMiddleware",
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"django.middleware.security.SecurityMiddleware",
\# Detect user's browser language and fwd. them to the best lang.
"django.middleware.locale.LocaleMiddleware",
"wagtail.contrib.redirects.middleware.RedirectMiddleware",
\]

ROOT_URLCONF = "website.urls"

TEMPLATES = \[
{
"BACKEND": "django.template.backends.django.DjangoTemplates",
"DIRS": \[
os.path.join(PROJECT_DIR, "templates"),
\],
"APP_DIRS": True,
"OPTIONS": {
"context_processors": \[
"django.template.context_processors.debug",
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
\],
},
},
\]

WSGI_APPLICATION = "website.wsgi.application"

# Database

# https://docs.djangoproject.com/en/4.1/ref/settings/#databases

DATABASES = {
"default": {
"ENGINE": "django.db.backends.sqlite3",
"NAME": os.path.join(BASE_DIR, "db.sqlite3"),
}
}

# Password validation

# https://docs.djangoproject.com/en/4.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = \[
{
"NAME": "django.contrib.auth.password_validation.UserAttributeSimilarityValidator",
},
{
"NAME": "django.contrib.auth.password_validation.MinimumLengthValidator",
},
{
"NAME": "django.contrib.auth.password_validation.CommonPasswordValidator",
},
{
"NAME": "django.contrib.auth.password_validation.NumericPasswordValidator",
},
\]

# Internationalization

# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = "en"
TIME_ZONE = "UTC"

# internationalisation in both Django and Wagtail

USE_I18N = True

# This will make dates and numbers display in the user’s local format

USE_L10N = True

WAGTAIL_I18N_ENABLED = True

USE_TZ = True

WAGTAIL_CONTENT_LANGUAGES = LANGUAGES = \[
('en', "English (Great Britain)"),
('cn', "Chinese"),
\]

WAGTAILLOCALIZE_SYNC_LIVE_STATUS_ON_TRANSLATE = False

# Static files (CSS, JavaScript, Images)

# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATICFILES_FINDERS = \[
"django.contrib.staticfiles.finders.FileSystemFinder",
"django.contrib.staticfiles.finders.AppDirectoriesFinder",
\]

STATICFILES_DIRS = \[
os.path.join(PROJECT_DIR, "static"),
\]

# ManifestStaticFilesStorage is recommended in production, to prevent outdated

# JavaScript / CSS assets being served from cache (e.g. after a Wagtail upgrade).

# See https://docs.djangoproject.com/en/4.1/ref/contrib/staticfiles/#manifeststaticfilesstorage

STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"

STATIC_ROOT = os.path.join(BASE_DIR, "static")
STATIC_URL = "/static/"

MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

# Wagtail settings

WAGTAIL_SITE_NAME = "website"

# Search

# https://docs.wagtail.org/en/stable/topics/search/backends.html

WAGTAILSEARCH_BACKENDS = {
"default": {
"BACKEND": "wagtail.search.backends.database",
}
}

# Base URL to use when referring to full URLs within the Wagtail admin backend -

# e.g. in notification emails. Don't include '/admin' or a trailing slash

WAGTAILADMIN_BASE_URL = "http://example.com"
Just_Stacking
  • 395
  • 3
  • 13

0 Answers0