Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

A django app that allows to swich the language based on the domain

Project description


A django app that allows to swich the language based on the domain the django server is accessed with.

You might be runing a site called and want to run the german version of the site under this app helps you doing this. You can configure what domain should be served in what language. You can also use it to configure language specific subdomains like and


Install the package with

python install

Add domain_lang to the installed apps


Add the Middleware after LocaleMiddleware


If you want to have access to the configured domains in your templates add domain_lang.context_processors.domain_language to the context_processors.

       'OPTIONS': {
            'context_processors': [

Finally run the migrations to create the database tables.

python migrate


After installing it and runing the django server you will find the DomainLanguageMappings in your admin. There you can configure the domains and their respecitve language. The Middleware will then always set the acitve language based on the domain of the reuqest. If no Mapping is configured for the active domain the language set by LocaleMiddleware will be in place.


You have to login for each domain seperatly. If you use subdomains for your langauge selection (,, ...) you can prepend the SESSION_COOKIE_DOMAIN with a dot, which will allow you to log in once for all subdomains.


Template Context

If you have added domain_lang.context_processors.domain_language to your context_processors, all Mappings will be provided in the variable called language_mappings. You can use this to show links to other versions of your site.

Template Tag

This app provides one template tag that allows you to translate a domain. It will also translate the domain part of the given url according to the configured mappgings

{% load domain_lang %}

{% translate_url '' 'de' %} # Might be translated to


django-domain-language is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program.  If not, see <>.

Project details

Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-domain-language, version 0.0.1
Filename, size File type Python version Upload date Hashes
Filename, size django_domain_language-0.0.1-py3-none-any.whl (22.6 kB) File type Wheel Python version py3 Upload date Hashes View hashes
Filename, size django-domain-language-0.0.1.tar.gz (6.5 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page