Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can i change django admin to rtl style

Tags:

python

django

First of all i'm new to django . and i'm amazing from this cool framework (not in database part and mysql connector)

And When i looking to django admin style folder in css folder ,

i see rtl css , but now i don't know how can i change admin style to rtl .

This is screen shot from my folders

enter image description here

Thank's

like image 275
majid Avatar asked Mar 27 '16 19:03

majid


People also ask

Can we change Django admin theme?

To do so, you will have to change the project's settings.py . Find the TEMPLATES section and modify accordingly. To override the default template you first need to access the template you want to modify from the django/contrib/admin/templates/admin directory.

Can I use Django admin as frontend?

As noted above, your own Django models can also present their fields for editing in the frontend. This is achieved by using the FrontendEditableAdminMixin base class.


2 Answers

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.

like image 148
Hojat Modaresi Avatar answered Sep 25 '22 00:09

Hojat Modaresi


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.

like image 33
Ian Price Avatar answered Sep 22 '22 00:09

Ian Price