سؤال

In the development environment, I set locale paths to:

LOCALE_PATHS = (
'/Users/***/Documents/Projects/**/Server/Django/**/locale',
)

But when I deploy it to server, locale path shold be changed.

How can I handle this?

هل كانت مفيدة؟

المحلول

to settings add

import os

LOCALE_PATHS = (
    os.path.join(os.path.dirname(__file__), "locale"),
)

نصائح أخرى

I am still currently using Django 1.5 and have found that I can handle it the easiest with the following:

LOCALE_PATHS = (
    'locale',
)

The following works better if you need to use an absolute path (indentation emphasized on purpose):

import os.path

LOCALE_PATHS = (
    os.path.abspath(
        os.path.join(
            os.path.dirname(__file__), 
                '..', "locale")),
)
  • First, the call to os.path.dirname returns the path to the directory of the settings file (__file__), e.g. /Users/foobar/projects/django-tutorial/mysite/mysite
  • Next, the call to os.path.join joins the previous result with a relative reference to a locale directory one level higher, e.g. /Users/foobar/projects/django-tutorial/mysite/mysite/../locale
  • Last, the call to os.path.abspath transforms the previous relative path reference to an absolute one, e.g. /Users/foobar/projects/django-tutorial/mysite/locale
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top