I am using this code in Django settings to construct the DB path
from os.path import expanduser
defautl_db_path = expanduser("~")+"/db.sqlite3"
The code runs well if I installed Django system wide but if I run the application inside virtualenv the application throws an exception saying unable to open database file.
How can I solve this?
did you check permissions on the home directory of the process owner? Is it true, that you are using a Unix OS?
Most likely the django user is www-data.
If you checked this, you could try to address home directory of a specific user by adding username to ~.
from os.path import expanduser
defautl_db_path = expanduser("~www-data")+"/db.sqlite3"
In documentation is written:
os.path.expanduser(path) On Unix and Windows, return the argument with an initial component of ~ or ~user replaced by that user‘s home directory.
On Unix, an initial ~ is replaced by the environment variable HOME if it is set; otherwise the current user’s home directory is looked up in the password directory through the built-in module pwd. An initial ~user is looked up directly in the password directory.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With