How to access directory file outside django project?

前端 未结 1 1354
我在风中等你
我在风中等你 2021-02-20 03:29

I have my Django project running on RHEL 7 OS. The project is in path /root/project. And project is hosted on httpd server. Now iam trying to access a file out side

1条回答
  •  再見小時候
    2021-02-20 04:28

    Add the following lines to your settings.py

    import os
    ..
    BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
    FILES_DIR = os.path.abspath(os.path.join(BASE_DIR, '../data/info'))
    

    Then you can use in your view

    from django.conf import settings
    import os
    ..
    file_path = os.path.join(settings.FILES_DIR, 'test.txt')
    

    0 讨论(0)
提交回复
热议问题