推荐学习书目
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 · Apr 18, 2012 · 4927 views
    This topic created in 5143 days ago, the information mentioned may be changed or developed.
    在这个文件中可以配置TEMPLATE_DIRS来自定义模块目录,但是注释中说一定要使用绝对路径。因为会在不同的电脑上开发同一个项目,请问大家怎么解决这个文件在版本库中的问题?
    7 replies    1970-01-01 08:00:00 +08:00
    xiaket
        1
    xiaket  
       Apr 18, 2012
    app下面建templates目录就行了?
    zzxworld
        2
    zzxworld  
    OP
       Apr 18, 2012
    @xiaket 不行的,因为要使用绝对路径,两台电脑中app的主目录不一致。
    c
        3
    c  
       Apr 18, 2012
    import os

    TEMPLATE_DIRS = (
    os.path.join(os.path.dirname(__file__), 'templates'),
    )
    bhuztez
        4
    bhuztez  
       Apr 18, 2012
    你随便搜一下就知道了,一般建议类似这样

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

    TEMPLATE_DIRS = (
    os.path.join(PROJECT_PATH, 'templates'),
    )
    zzxworld
        5
    zzxworld  
    OP
       Apr 18, 2012
    @c
    @bhuztez
    茅塞顿开,谢了。
    bhuztez
        6
    bhuztez  
       Apr 18, 2012
    @c 建议用 import os.path,还真碰到过 import os 之后 os.path 没的情况。
    c
        7
    c  
       Apr 18, 2012
    @bhuztez 谢谢提醒,我学的比较晚,最早的版本就是2.5,一直都是import os,以后要改一改。
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3538 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 00:14 · PVG 08:14 · LAX 17:14 · JFK 20:14
    ♥ Do have faith in what you're doing.