The guy here already asked about this and solved it by deleting 500.html
and 404.html
.
Same for me, when DEBUG
is True
everything works as expected: Wagtail redirects /
to /en
, on non-existing pages it gives 404 and so on.
Now when DEBUG
is False
when accessing /
it returns 500 error without any error (only Internal Server Error: /
, and I have LOGGING
enabled, logfile has no errors either). If I delete 500.html
and 404.html
everything works, which is strange...
urls.py
urlpatterns = [
# path('django-admin/', admin.site.urls),
path('i18n/', include('django.conf.urls.i18n')),
path('admin/', include(wagtailadmin_urls)),
path('documents/', include(wagtaildocs_urls)),
path('search/', search_views.search, name='search'),
]
urlpatterns += i18n_patterns(
path("search/", search_views.search, name="search"),
path("", include(wagtail_urls)),
)
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)
In MIDDLEWARE
there is 'wagtail.contrib.redirects.middleware.RedirectMiddleware',
Also I noticed that the issue is in 404.html
, when using django templates, extends
, block
etc. Redirects dont work, if 404.html
is plain html - redirects work...
In Wagtail's issues on github there is kind of similar issue - #6587. I have the same behavior when DEBUG = False
- Wagtail works when accessing "exactly that URL", redirects won't work.
Deleting 404 and 500 error templates is not great in production. Is there any solution to this?