Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8199801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T06:14:43+00:00 2026-06-07T06:14:43+00:00

I’ve setup translated urls for some languages. The default language for django has been

  • 0

I’ve setup translated urls for some languages. The default language
for django has been set to en-US.

If you request a page /registration/ with nl-NL as Accept-Language
header, I get a 404.
I wasn’t expecting such behaviour. Rather I was hoping I would be
redirected to /registratie/ ,the tranlated url that corresponds my
Accept-Language header.
Ofcourse /registratie/ with the nl-Nl Accept-Language header, works
fine and gives me the expected 200.

I’m guessing this is just as normal as it can get ?

Isn’t there a chance a user might get link from some website and
the link is build for the English language, but the user in question
has a different supported language setting, Accept-Language header ?
In such a case he would be presented with a 404.
He should be presented with or the English (default) content or
or be redirected to the correct url for his language if supported.

Also what happens if a user has a not supported language setting ?
Will the django default LANGUAGE_CODE be used, en-US in my case ?

Is there a way to work around this or handle it in a different better way ?

an extract from my urls.py file, shows how I’ve setup translated urls:

url(_(r'^step1/$'), AccountTypeSelectionView.as_view(), name="registration_step1"),
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-07T06:14:44+00:00Added an answer on June 7, 2026 at 6:14 am

    I’m making a wild assumption that _ is ugettext_lazy.

    Also what happens if a user has a not supported language setting ? Will the django default LANGUAGE_CODE be used, en-US in my case ?

    Yes, ugettext will use the default value if no specific value is set. You can see this behaviour in do_translate in django.utils.translation.trans_real.

    What happens with ugettext_lazy is that just prior to the URL being looked up, it is translated to the user’s language and then the part of the URL is checked against all these. (Django uses a per-thread language setting that is changed to reflect the user’s choices.)

    Isn’t there a chance a user might get link from some website and the link is build for the English language, but the user in question has a different supported language setting, Accept-Language header ? In such a case he would be presented with a 404. He should be presented with or the English (default) content or or be redirected to the correct url for his language if supported.

    Well, yes I believe that should be a supported feature but a quick look at the source made it appear that URL resolving would have to be changed a bit to accomodate this.

    What you can do, is use a custom 404 page (as briefly mentioned here under Customizing error views):

    in your urls.py:

    handler404 = 'mysite.views.i18n_retry'
    

    and in a view

    from django.utils.translation import override
    from django.core.urlresolvers import resolve
    def i18n_retry(request):
        for language in settings.LANGUAGES:
            with override(language, deactivate=True):
               try:
                  result = resolve(request.path)
                  #here you will know what language the url is in
                  #if it is a supported format
                  #and can do something smart about it
               except Http404:
                  #Http404 is thrown whenever resolving fails
                  pass
         #here you should probably return a real 404
    

    I’ve used the override context manager from Django 1.4. but there is a longer way of doing the same without.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
Basically, what I'm trying to create is a page of div tags, each has
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.