Default language via settings not respected during testing

前端 未结 2 1935
抹茶落季
抹茶落季 2021-01-18 11:25

Using Django 1.3, Python 2.6

Having a particularly weird problem to track down related to internationalization, and RequestFactory vs. TestClient for testing views

2条回答
  •  旧巷少年郎
    2021-01-18 12:06

    There are 2 possibilities :

    a) You have 'django.middleware.locale.LocaleMiddleware' in settings.MIDDLEWARE_CLASSES.

    In this case, the client use settings.LANGUAGE_CODE.

    b) You don't.

    In that case, you should set the language like that somewhere in your tests.py module:

    from django.utils.translation import activate
    ...
    activate('fr-fr')
    

    https://code.djangoproject.com/ticket/15143

提交回复
热议问题