Change locale for django-admin-tools

2024/11/15 11:47:45

In my settings.py file I have:

LANGUAGE_CODE = 'ru-RU'

also, I have installed and working django-admin-tools. But admin language still english. What I'm doing wrong?

PS.

$ cat settings.py | grep USE | grep -v USER
USE_I18N = True
USE_L10N = True
USE_TZ = True
Answer

You need to set the language specifically for the admin app. Since django does not provide a language drop down as part of the default login, you have a few options:

  1. Login to your normal (non admin view), with superuser/staff credentials and the correct language, then shift over to the admin URL.

  2. Update the admin templates and add a language dropdown see this snippet.

  3. Create some custom middleware to set the language for admin:

    from django.conf import settings
    from django.utils import translationclass AdminLocaleMiddleware:def process_request(self, request):if request.path.startswith('/admin'):request.LANG = getattr(settings, 'ADMIN_LANGUAGE_CODE',settings.LANGUAGE_CODE)translation.activate(request.LANG)request.LANGUAGE_CODE = request.LANG
    

    Add it to your MIDDLEWARE_CLASSES

    MIDDLEWARE_CLASSES = {# ...'foo.bar.AdminLocaleMiddleware',# ...
    }
    

    Set the language you want for the admin in settings.py:

    ADMIN_LANGUAGE_CODE = 'ru-RU'
    
https://en.xdnf.cn/q/72124.html

Related Q&A

Container localhost does not exist error when using Keras + Flask Blueprints

I am trying to serve a machine learning model via an API using Flasks Blueprints, here is my flask __init__.py filefrom flask import Flaskdef create_app(test_config=None):app = Flask(__name__)@app.rout…

Serving static files with WSGI and Python 3

What is the simplest way to serve static files with WSGI and Python 3.2? There are some WSGI apps for PEP 333 and Python 2 for this purpose - but was is about PEP 3333 and Python 3? I want to use wsg…

Force INNER JOIN for Django Query

Here is my schema:City PhotographerIm trying to get a list of cities that have at least one photographer, and return the photographer count for the cities.Here is the queryset Im working with:City.obj…

Sklearn Decision Rules for Specific Class in Decision tree

I am creating a decision tree.My data is of the following typeX1 |X2 |X3|.....X50|Y _____________________________________ 1 |5 |7 |.....0 |1 1.5|34 |81|.....0 |1 4 |21 |21|.... 1 |0 65 |34 |23|..…

Cubic hermit spline interpolation python

I would like to calculate a third-degree polynomial that is defined by its function values and derivatives at specified points.https://en.wikipedia.org/wiki/Cubic_Hermite_splineI know of scipys interpo…

Increase Accuracy of float division (python)

Im writing a bit of code in PyCharm, and I want the division to be much more accurate than it currently is (40-50 numbers instead of about 15). How Can I accomplish this?Thanks.

Twitter API libraries for desktop apps?

Im looking for a way to fetch recent posts from twitter. Really I just want to be able to grab and store new posts about a certain topic from twitter in a text file. Are there any current programs or l…

How to generate a PDF from an HTML / CSS (including images) source in Python? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, argum…

Modify subclassed string in place

Ive got the following string subclass:class S(str):def conc(self, next_val, delimiter = ):"""Concatenate values to an existing string"""if not next_val is None:self = sel…

sum numpy ndarray with 3d array along a given axis 1

I have an numpy ndarray with shape (2,3,3),for example:array([[[ 1, 2, 3],[ 4, 5, 6],[12, 34, 90]],[[ 4, 5, 6],[ 2, 5, 6],[ 7, 3, 4]]])I am getting lost in np.sum(above ndarray ,axis=1), why …