Django: get the path to the current django app
I have a Django app with some management commands. In one of those commands, I need to write a log file which is located in /logs allong side views.py, models.py, etc ...
Considering that my managemen开发者_如何学Ct command script is in /management/commands/mycommand.py, is there any reliable way to determine the location of the appdir from within mycommand.py ?
PS: by reliable, I mean without using os.path.abspath( __file__ )
, because the location of the file might change later on.
That's what your settings are for.
Add this to your settings
MY_APP_LOG_DIRECTORY = "path/to/logs"
In your view functions, use
from django.conf import settings
Now you can use settings.MY_APP_LOG_DIRECTORY
all you want.
精彩评论