question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Redirects do not work when using Django's i18n_patterns() wrapper

See original GitHub issue

Issue 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

  1. Set up a standard wagtail install
  2. follow the wagtail instructions on turning on internationalisation, with at least on LANGUAGES entry, I’d recommend en-us.
  3. create a redirect for /test to the homepage.
  4. navigate to localhost:8000/test and observe it redirecting to localhost:8000
  5. navigate to localhost:8000/es-us/test
  6. 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:closed
  • Created 3 years ago
  • Comments:10 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
Pomaxcommented, Jan 4, 2021

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.

0reactions
lb-commented, Aug 12, 2022

@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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found