我刚刚为我的公司开始了关于Django的可行性研究,我注意到settings.py上需要绝对路径:
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
)
Run Code Online (Sandbox Code Playgroud)
我的问题是:当你与团队合作时,如何处理这些绝对的路径?比如说,如果团队成员在从源代码控制获取项目后必须修改路径,那么这不仅会出错,而且浪费时间,但是当用户必须对settings.py进行更改时,这也会导致复杂化.我怎么能避免这个?
Blu*_*ers 30
import os.path
#Get the absolute path of the settings.py file's directory
PWD = os.path.dirname(os.path.realpath(__file__ ))
TEMPLATE_DIRS = (
# Put strings here, like "/home/html/django_templates" or
# "C:/www/django/templates".
# Always use forward slashes, even on Windows.
# Don't forget to use absolute paths, not relative paths.
#Add Templates to the absolute directory
os.path.join(PWD, "Templates")
)
Run Code Online (Sandbox Code Playgroud)
这就是我做相对进口的方式.请注意,通常明智的做法是使用单独的localsettings.py文件或类似文件.
| 归档时间: |
|
| 查看次数: |
11856 次 |
| 最近记录: |