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 thoughts on “Django: Finding the current project’s path

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s