V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
zzxworld
V2EX  ›  Python

django中的settings.py

  •  
  •   zzxworld · 2012-04-18 20:38:32 +08:00 · 4247 次点击
    这是一个创建于 4391 天前的主题,其中的信息可能已经有所发展或是发生改变。
    在这个文件中可以配置TEMPLATE_DIRS来自定义模块目录,但是注释中说一定要使用绝对路径。因为会在不同的电脑上开发同一个项目,请问大家怎么解决这个文件在版本库中的问题?
    7 条回复    1970-01-01 08:00:00 +08:00
    xiaket
        1
    xiaket  
       2012-04-18 20:41:26 +08:00
    app下面建templates目录就行了?
    zzxworld
        2
    zzxworld  
    OP
       2012-04-18 20:48:58 +08:00
    @xiaket 不行的,因为要使用绝对路径,两台电脑中app的主目录不一致。
    c
        3
    c  
       2012-04-18 20:49:05 +08:00
    import os

    TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates'),
    )
    bhuztez
        4
    bhuztez  
       2012-04-18 20:49:15 +08:00
    你随便搜一下就知道了,一般建议类似这样

    PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

    TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates'),
    )
    zzxworld
        5
    zzxworld  
    OP
       2012-04-18 20:50:35 +08:00
    @c
    @bhuztez
    茅塞顿开,谢了。
    bhuztez
        6
    bhuztez  
       2012-04-18 20:53:28 +08:00
    @c 建议用 import os.path,还真碰到过 import os 之后 os.path 没的情况。
    c
        7
    c  
       2012-04-18 20:56:25 +08:00
    @bhuztez 谢谢提醒,我学的比较晚,最早的版本就是2.5,一直都是import os,以后要改一改。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1699 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 17:08 · PVG 01:08 · LAX 10:08 · JFK 13:08
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.