django project root self discovery

前端 未结 4 883
灰色年华
灰色年华 2020-12-03 09:45

Ok so I recall there are some commands you could put in the settings.py file so that basically when you move your django project to another directory it won\'t

4条回答
  •  误落风尘
    2020-12-03 10:15

    Django 1.8 already includes the project root directory as BASE_DIR:

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

    And you can use it in your app by importing settings:

    from django.conf import settings
    ...
    ...
    print(settings.BASE_DIR)
    

提交回复
热议问题