Redirects do not work when using Django's i18n_patterns() wrapper
See original GitHub issueIssue Summary
When using Wagtail wrapped by Django’s i18n_patterns
, redirects only work for “exactly that URL” instead of also for the localised versions. E.g. /from-page => /to-page
only works for http://site/from-page
but not http://site/en-us/from-page
.
Steps to Reproduce
- Set up a standard wagtail install
- follow the wagtail instructions on turning on internationalisation, with at least on
LANGUAGES
entry, I’d recommenden-us
. - create a redirect for
/test
to the homepage. - navigate to
localhost:8000/test
and observe it redirecting tolocalhost:8000
- navigate to
localhost:8000/es-us/test
- this is a 404 instead of redirecting properly
- I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: yes
The fix for this is updating the wagtail.contrib.redirects middleware to, in _get_redirect
, remove the locale prefix from the path to resolve, if request.LANGUAGE_CODE
exists.
Technical details
- Python version: 3.7.7
- Django version: 3.1
- Wagtail version: 2.11.2
- Browser version: irrelevant
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (9 by maintainers)
Top Results From Across the Web
new locale not redirecting properly - django - Stack Overflow
I have a basic django cms running with lots of localised content. I have been assigned to add few more languages before content...
Read more >[Django] #24085: @requires_login decorator redirects to a ...
[Django] #24085: @requires_login decorator redirects to a locale specific URL when using i18n_patterns. 11 views.
Read more >The Ultimate Guide to Django Redirects - Real Python
In this detailed guide, you'll learn everything you need to know about HTTP redirects in Django. All the way from the low-level details...
Read more >Translation | Django documentation
Marking strings as no-op¶. Use the function django.utils.translation.gettext_noop() to mark a string as a translation string without translating it. The ...
Read more >Translation - Django 1.4 documentation
If you don't use internationalization, you should take the two seconds to set ... Use the function django.utils.translation.ugettext_noop() to mark a string ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
fair enough, but note that the docs still tell folks to use either wagtailtrans or wagtail-modeltranslations over on https://docs.wagtail.io/en/stable/advanced_topics/i18n.html?highlight=localization#alternative-internationalisation-plugins if they need an alternative, meaning it’s basically one of the two official recommendations.
@raminjrmz this issue has been closed for some time - see above comments.
I recommend you start a discussion about your problem and see if others can provide a work around. Or if you feel there is a bug that is not covered by this response above - maybe a new bug is needed.