[Fixed]-How can i change django admin to rtl style

11👍

Try setting your language code in settings:

LANGUAGE_CODE = 'fa-ir'

for further reading on translating, rtl, changing date format and other localization things read this django doc.

4👍

Django looks at the TEMPLATES setting to find order to check for templates to render. As such, you can add rtl.css to the head of the base admin template in order to load the right-to-left css.

  1. In a templates sub-directory of your main project directory, create dir admin and file base.html. Copy the contents of ‘django/contrib/admin/templates/base.html’ from Django’s source to the newly created file.

    TEMPLATES = [
    {
    'BACKEND': 'django.template.backends.django.DjangoTemplates',
    'DIRS': [os.path.join(BASE_DIR, 'templates')], # <- add this line
    'APP_DIRS': True,
    'OPTIONS': {
    'context_processors': [
    'django.template.context_processors.debug',
    'django.template.context_processors.request',
    'django.contrib.auth.context_processors.auth',
    'django.contrib.messages.context_processors.messages',
    ],
    },
    },
    ]

  2. In the template, you’ll see {% block extra_head %}{% endblock %}. Insert the stylesheet link here, like this-

    {% block extra_head %}
    <link rel='stylesheet' href='{% static 'admin/css/rtl.css' %}' />
    {% endblock %}

Now rtl.css will be loaded whenever any admin page is loaded.

Leave a comment