django project root self discovery

前端 未结 4 865
灰色年华
灰色年华 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:28

    The architecture of a project in Django

    • root/

      • app1/
      • app2/
      • ...
      • main/
        • settings.py

    Inside settings.py:

    SITE_ROOT = os.path.dirname(os.path.realpath(__file__)) -> gives the path of the file settings.py: root/main/. This is NOT THE ROOT OF THE PROJECT

    PROJECT_PATH = os.path.abspath(os.path.dirname(__name__)) -> gives the root of the project: root/. This is THE ROOT OF THE PROJECT.

提交回复
热议问题