[Answered ]-Where does python get the value for path when running Django/WSGI

2👍

You should never rely on the current working directory being a specific location in web applications because what it will be will be different for different hosting mechanisms. So, don’t even try to change the current working directory as it will only lead to grief eventually by then relying on that.

Instead you should organise your code to use an absolute path. This would need to be either hard coded, be added as a suffix to some prefix from configuration, or calculated on the fly relative to the location of the code file being executed. In the latter you would do:

import os
here = os.path.dirname(__file__)
path = os.path.join(here, 'relative/path/file.txt')

Leave a comment