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 720473
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T05:45:43+00:00 2026-05-14T05:45:43+00:00

How to explicitly set django_language in Django session? Thanks a lot…

  • 0

How to explicitly set django_language in Django session?

Thanks a lot…

  • 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-14T05:45:43+00:00Added an answer on May 14, 2026 at 5:45 am

    If you want your users to be able to specify language, make sure that LocaleMiddleware is enabled:

    MIDDLEWARE_CLASSES = (
       ...
       'django.middleware.locale.LocaleMiddleware',
       ...
    )
    

    Then Django will look for the user’s language preference in that order (see get_language_from_request in trans_real.py):

    1. in request.path_info, if i18n_patterns are used
    2. request.session[settings.LANGUAGE_SESSION_KEY] (DEPRECATED in Django 3.0, removed in Django 4.0)
    3. request.COOKIES[settings.LANGUAGE_COOKIE_NAME]
    4. every language in request.META['HTTP_ACCEPT_LANGUAGE'], until accepted one is found
    5. settings.LANGUAGE_CODE.

    As of Django 4.0

    The most straightforward way to set language explicitly in Django session is to activate and set the cookie, see the docs:

    from django.conf import settings
    from django.http import HttpResponse
    from django.utils import translation
    
    user_language = 'fr'  # example
    translation.activate(user_language)
    
    # persist using the cookie
    response = HttpResponse(...)
    response.set_cookie(settings.LANGUAGE_COOKIE_NAME, user_language)
    

    Before Django 4.0

    The most straightforward way to set language explicitly in Django session is to rewrite request.session[settings.LANGUAGE_SESSION_KEY]:

    def someview (request):
        ...
        request.session[settings.LANGUAGE_SESSION_KEY] = 'en'
        ...
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 357k
  • Answers 357k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Try adding an onsubmit to your form tag: <form action="enterdb.php"… May 14, 2026 at 9:01 am
  • Editorial Team
    Editorial Team added an answer The Apache MINA Networking framework is built on NIO (and… May 14, 2026 at 9:01 am
  • Editorial Team
    Editorial Team added an answer I think you want this book: Physics for Game Developers. May 14, 2026 at 9:01 am

Related Questions

I'm currently looking at the the documentation for Django sites: http://docs.djangoproject.com/en/dev/ref/contrib/sites/#ref-contrib-sites which explains how
I have a pretty standard django app, and am wondering how to set the
I have a blog written in Django, and I started using the basic Django
I'm rather new to jQuery and I'm trying to make a cool little menu
I am adding elements to an XML file during installation using the XmlFile element:

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.