Django paths, developing in windows, deploying on linux

后端 未结 4 1039
悲哀的现实
悲哀的现实 2021-02-09 10:47

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

4条回答
  •  一生所求
    2021-02-09 10:55

    Add

    import os.path
    
    BASE_PATH = os.path.dirname(__file__)
    

    at the top of your settings file, and then use BASE_PATH everywhere you want to use a path relative to your Django project.

    For example:

    MEDIA_ROOT = os.path.join(BASE_PATH, 'media')
    

    (You need to use os.path.join(), instead of simply writing something like MEDIA_ROOT = BASE_PATH+'/media', because Unix joins directories using '/', while windows prefers '\')

提交回复
热议问题