I’m developing Django apps on my local windows machine then deploying to a hosted linux server. The format for paths is different between the two and manually replacing before deployment is consuming more time than it should. I could code based on a variable in my settings file and if statements but I was wondering if anyone had best practices for this scenario.
I’m developing Django apps on my local windows machine then deploying to a hosted
Share
The Django book suggests using
os.path.join(and to use slashes instead of backslashes on Windows):I think this is the best solution as you can easily create relative paths like that. If you have multiple relative paths, a helper function will shorten the code:
If you need absolute paths, you should use an environment variable (with
os.environ["MY_APP_PATH"]) in combination withos.path.join.