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

  • Home
  • SEARCH
  • 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 7130073
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:18:40+00:00 2026-05-28T11:18:40+00:00

I have a rather simple informational website that’s being run by Django. Its’ pages(views)

  • 0

I have a rather simple informational website that’s being run by Django.

Its’ pages(views) are rendered by a render_to_response shortcut that is used like this:

def index(request):  
    return render_to_response(**create_render_args('Index.html', request))

def somepage(request):
    return render_to_response(**create_render_args('Somepage.html', request, _(u'Some page title'), 'somepage.css'))

# other pages are also rendered in that way

Where create_render_args function is:

def create_render_args(html, request, title = _(u'Default title'), page_css = ''):
    return {
        'template_name' : html,
        'dictionary' :
            {
                'title' : title,
                'page_css' :  '' if page_css == '' else '<link rel="stylesheet" href="/css/{}" />'.format(page_css),
                # other template variables...
            }, 
        'context_instance' : RequestContext(request)
    }

Essentialy it’s a simple way I use to avoid extra code, avoid creating extra template blocks and still be able to specify unique CSS and a localized page title for each language the site is translated into (it’s localized into 4). Maybe there are better ways to do this but I must admit that my Django experience is still rather limited on this matter – I would like to hear any objective criticism.

The problem is that when I use ugettext as _, and I navigate / switch languages / reload pages, it seems that sometimes ‘title’ variable that is being used in template gets ‘stuck’ in old language even though the page itself is already translated into the new language.

For example, if the site is in italian, I open the main page, the title is proper.
Then I switch to english (my javascript that handles the language switch reloads the page), the title is still italian even though everything else is in english. I navigate to another page and navigate to main page again, reload the page a few times – title is italian, page is in english. I go to the server console, touch the wsgi file (to reload Django manually) – main page is fully english on the next reload. But then, I switch the language to italian again – the page is in italian, the title is in english.

Sometimes the behavior is even more odd — if I keep reloading the page by pressing F5, I might get its’ title from the previous language 2 times in a row, then the correct title gets out for a single time, and then I get ‘old’ title on the following reloads.

Now what troubles me the most – if I use ugettext_lazy as _, I have no problems at all. The title is always in the same language as the rest of the page.

As far as I know, views are being called on each page view, so something I believe I encounter – create_render_args()‘s output for each given page being cached somewhere and returning the same dictionary all the time – shouldn’t be possible.

What could be the source of this problem? What am I missing?

  • 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-05-28T11:18:40+00:00Added an answer on May 28, 2026 at 11:18 am

    This is the old Python default arguments gotcha once again.

    The default values for the create_render_args function are evaluated when the function is first imported, which is probably when the server process starts up. Processes in WSGI last for multiple requests, which explains why the value is cached between views, but there are usually multiple processes running at once, which explains why sometimes you see the correct version.

    I’m not sure why using ugettext_lazy isn’t the answer for you – that seems to be exactly its use case – but otherwise you could just use the raw text itself as the default and do the _ call within the function.

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

Sidebar

Related Questions

I have a java application that needs to connect to a server. Its rather
I have a rather simple piece of code that is hanging in java. The
I have a rather simple threading question. I'm writing a simple utility that will
We have a rather simple site (minimal JS) with plain html and CSS. It
I will try to keep this as simple as possible. I have a rather
Heavy emphasis on simple. I've never made an installer and I'd rather not have
I'm rather new to WPF, so maybe this is a simple question. I have
I have rather large input XML files that must be converted to a given
I have a rather big number of source files that I need parse and
I have a table that defines the possible categories in my website - fields

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.