Django:配置设置.py依赖相对路径而不是绝对路径

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Django:配置设置.py依赖相对路径而不是绝对路径相关的知识,希望对你有一定的参考价值。

Hate absolute Paths? Me too, I always end up forgetting to change things around when I go into production mode. Thankfully, there's a nice, clean way to have Python do all the hard work.
  1. import os.path
  2. PROJECT_DIR = os.path.dirname(__file__)
  3.  
  4.  
  5. #Here are examples of how you can set your MEDIA_ROOT and TEMPLATE_DIRS
  6. MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media')
  7.  
  8. TEMPLATE_DIRS = (
  9. os.path.join( PROJECT_DIR, 'templates' ),
  10. )

以上是关于Django:配置设置.py依赖相对路径而不是绝对路径的主要内容,如果未能解决你的问题,请参考以下文章