zoukankan      html  css  js  c++  java
  • 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/..')



  • 相关阅读:
    [MySql]insert...select 8/10
    秀出Administrator帳戶6/27
    Love
    讀取Gridview的隱藏欄8/22
    水晶報表公式換行8/2
    MySql.Data.MySqlClient.MySqlException 7/9
    mysql的錯誤日誌爆满7/24
    从汇编看c++中的const常量
    可见性和生命期的区别
    比较烦
  • 原文地址:https://www.cnblogs.com/BlueFire-py/p/8833255.html
Copyright © 2011-2022 走看看