Django: Finding the current project’s path

Problem: You need the filesystem location of the current project, but your code doesn’t know which project is is used by (think 3rd party app).

Answer:  Define “project location” as “location of settings file”, and you can do:

from django.conf import settings
os.path.dirname(os.path.normpath(os.sys.modules[settings.SETTINGS_MODULE].__file__))

3 Responses to “Django: Finding the current project’s path”

  1. Frank Malina Says:

    Thank you, that’s just what I needed.

  2. Conan Albrecht Says:

    Thanks! This saved me the headache of trying to put all those os.path… together.

  3. Cristopher Jefferson Says:

    wonderful, it is what i have been looking for

Leave a Reply