[Fixed]-Recommended way of accessing BASE_DIR in Django

31👍

This isn’t a question about BASE_DIR, but about importing settings. Your proposed solution is not valid Python in any case: imports don’t use file paths like that.

The standard and fully documented way of importing settings in Django is this:

from django.conf import settings

This will always work, in any Django project, and will allow you to access any of the settings.

2👍

For example, in a views.py file, we can do the following to use the value of BASE_DIR

from django.conf import settings
value = settings.BASE_DIR

Leave a comment