to settings add
import os
LOCALE_PATHS = (
os.path.join(os.path.dirname(__file__), "locale"),
)
题
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")),
)
os.path.dirname
returns the path to the directory of the settings file (__file__
), e.g. /Users/foobar/projects/django-tutorial/mysite/mysite
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
os.path.abspath
transforms the previous relative path reference to an absolute one, e.g. /Users/foobar/projects/django-tutorial/mysite/locale