Skip to main content

User g11n extension for Django

Project description

Django User g11n


Django supports i18n and l10n. However, there is no item to set the user's time zone and region as a default feature.

Django User g11n (globalization) provides fields for users to set time zones and regions, as well as middleware to handle them properly.

Core idea is See the Django documentation for more information

  • Support 3
  • Support Python3.9 (Maybe 2.7. 3.8)


Install the package from pypi

$ pip install django-user-g11n

Next, choose one of the following two implementation methods

  • Using a profile model
  • Using a custom user model

The profile model refers to a model that handles information about a user that is connected to the Django user model by a OneToOneField. If you are already recommending this method of implementation, see If you are using a profile model.

A custom user model is a way of extending the Django user model itself to contain data. To get users to take advantage of the custom model, you create an application and customize the model. See the Django documentation for more information

Using a profile model

Create an application that handles the profile model.

$ startapp accounts

Add the following to your application's

from django.db import models
from user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin

class UserProfile(UserTimeZoneSupportMixin,

    user = models.OneToOneField(

Using a custom user model

Create an application for custom users. Please refer to the Django documentation for more information. See the Django documentation for more information

$ startapp accounts

Add the following to your application's

from django.contrib.auth import models as auth_models
from user_g11n.models import UserLanguageSupportMixin, UserTimeZoneSupportMixin

class User(UserTimeZoneSupportMixin,

modifying to


Add a user-extended application and user_g11n to INSTALLED_APPS.

    'accounts',  # Your Custom user model application
    'user_g11n', # Add


Added two middleware provided by django_user_g11n.

    'user_g11n.middleware.UserLanguageMiddleware', # Add
    'user_g11n.middleware.UserTimeZoneMiddleware', # Add


Change or add the AUTH_USER_MODEL.

AUTH_USER_MODEL = 'accounts.User'

I18N, L10N & TIME_ZONE setting

Change the I18N, L10N, and TZ settings.

USE_I18N = True

USE_L10N = True

USE_TZ = True

TIME_ZONE = "Asia/Tokyo" # Change to your local timezone

When a profile model is used (specification of profile attributes)

Set the attribute name of the profile model associated with the user model.


If the related_name is "foobar" in the OneToOneField to the user model specified in the profile model, change the value here to the following



Migration to adapt the changes.

$ ./ makemigrations
$ ./ migrate


The Docker configuration is provided. Please use the following command to start it. Go to http://localhost:8000 when the launch is complete.

$ docker-compose up


See this

Project details

Download files

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

Files for django-user-g11n, version 0.4.1
Filename, size File type Python version Upload date Hashes
Filename, size django_user_g11n-0.4.1-py3-none-any.whl (6.6 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size django-user-g11n-0.4.1.tar.gz (6.4 kB) File type Source Python version None Upload date Hashes View

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring DigiCert DigiCert EV certificate Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page