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?
我怎么处理这个?
2 个解决方案
#1
6
to settings add
设置添加
import os
LOCALE_PATHS = (
os.path.join(os.path.dirname(__file__), "locale"),
)
#2
4
I am still currently using Django 1.5 and have found that I can handle it the easiest with the following:
我目前仍在使用Django 1.5并且发现我可以使用以下方法处理它最简单:
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
- 首先,对os.path.dirname的调用返回设置文件(__file__)目录的路径,例如, /用户/ foobar的/项目/ Django的教程/ mysite的/ mysite的
- Next, the call to
os.path.join
joins the previous result with a relative reference to alocale
directory one level higher, e.g./Users/foobar/projects/django-tutorial/mysite/mysite/../locale
- 接下来,对os.path.join的调用将前一个结果与一个更高级别的语言环境目录的相对引用连接起来,例如, /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
- 最后,对os.path.abspath的调用将先前的相对路径引用转换为绝对路径引用,例如, /用户/ foobar的/项目/ Django的教程/ mysite的/区域设置
#1
6
to settings add
设置添加
import os
LOCALE_PATHS = (
os.path.join(os.path.dirname(__file__), "locale"),
)
#2
4
I am still currently using Django 1.5 and have found that I can handle it the easiest with the following:
我目前仍在使用Django 1.5并且发现我可以使用以下方法处理它最简单:
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
- 首先,对os.path.dirname的调用返回设置文件(__file__)目录的路径,例如, /用户/ foobar的/项目/ Django的教程/ mysite的/ mysite的
- Next, the call to
os.path.join
joins the previous result with a relative reference to alocale
directory one level higher, e.g./Users/foobar/projects/django-tutorial/mysite/mysite/../locale
- 接下来,对os.path.join的调用将前一个结果与一个更高级别的语言环境目录的相对引用连接起来,例如, /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
- 最后,对os.path.abspath的调用将先前的相对路径引用转换为绝对路径引用,例如, /用户/ foobar的/项目/ Django的教程/ mysite的/区域设置