flask-----No such file or directory絕對路徑與相對路徑


No such file or directory: '\\uploads\\03.jpeg'

相對路徑:加點,或者直接絕對路徑(盡量使用絕對路徑,通過python的os模塊獲取當前文件絕對路徑)

os.path.dirname(os.path.abspath(__file__))  返回的是文件的目錄

os.path.abspath(__file__)返回的是.py文件的絕對路徑,包含文件名,並且返回path規范化的絕對路徑

 

 

 

相對路徑

../表示源文件所在目錄的上一級目錄,../../表示源文件所在目錄的上上級目錄,以此類推。
同級目錄直接文件名可以直接引用
./下一級目錄

來自stackoverflow

Both /tmp and /static/uploads/.., are absolute paths. And your code is looking in the / folder instead of looking in your project's folder. You should use the absolute path to point at your folder /path/to/your/project/static/uploads/.. or use a path relative to the code being executed such as ./static/uploads.

You can also use the following snippet to generate the absolute path:

from os.path import join, dirname, realpath UPLOADS_PATH = join(dirname(realpath(__file__)), 'static/uploads/..')




免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM