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/..')
flask-----No such file or directory绝对路径与相对路径的更多相关文章
- 无后缀名伪静态路径在IIS7.0的网站提示 "404 - File or directory not found"
新配置服务器(windows server 2008,not sp1) 经测试情况如下: ①无后缀名伪静态路径行在IIS7.0的网站提示 ”404 - File or directory not fo ...
- STM32 关于头文件路径没添加错误问题(cannot open source input file "spi.h": No such file or directory)
error: #5: cannot open source input file "spi.h": No such file or directory 1.出现这种问题,首先要确 ...
- R中读取文件,找不到路径问题 No such file or directory
R中读取文件,找不到路径问题 No such file or directory 近日,读取文件时.出现例如以下问题 > passenger = read.csv('internationa ...
- Git异常:fatal: could not create work tree dir 'XXX': No such file or directory
GitHub实战系列汇总:http://www.cnblogs.com/dunitian/p/5038719.html ———————————————————————————————————————— ...
- Warning: mysql_connect(): No such file or directory 解决方案总结(操作系统: Mac)
说明: 本文主要内容参考: Mac下PHP连接MySQL报错"No such file or directory"的解决办法, 并进行个人补充 1. 运行环境: Mac OS X 10.11.4 (M ...
- error while loading shared libraries: libmysqlclient.so.18: cannot open shared object file: No such file or directory
zabbix3.2启动有如下报错: # service zabbix_server startStarting zabbix_server: /home/zabbix-server/sbin/zab ...
- RHEL 5.7 Yum配置本地源[Errno 2] No such file or directory
在Red Hat Enterprise Linux Server release 5.7 上配置YUM本地源时,遇到了"Errno 5] OSError: [Errno 2] No such ...
- 问题解决:psql: could not connect to server: No such file or directory Is the server running locally and accepting connections on Unix domain socket "/var/run/postgresql/.s.PGSQL.5432"?
错误提示: psql: could not connect to server: No such file or directory Is the server running locally and ...
- 执行Python "/bin/usr/python: bad interpreter: No such file or directory" 错误
今天在电脑上写了一个Python脚本,写好之后用ftp传上去,然后执行/var/www/cron.py,结果报错,/bin/usr/python: bad interpreter: No such f ...
随机推荐
- 注解:@interface 自定义注解的语法
自定义注解: 使用@interface自定义注解时,自动继承了java.lang.annotation.Annotation接口,由编译程序自动完成其他细节.在定义注解时,不能继承其他的注解或接口 ...
- 安装zabbix-agent报错 Error: failure: repodata/primary.xml.gz from zabbix: [Errno 256] No more mirrors to try.
安装zabbix-agent报错 yum install -y zabbix-agent Loaded plugins: fastestmirror, refresh-packagekit, secu ...
- 解决实现OnPageChangeListener()接口的方法参数出现arg0,arg1的现象
在安卓开发中,我们经常用到ViewPager,那么既然用到ViewPager,一般都需要去实现OnPageChangeListener()接口的三个方法. 但是有时候实现的三个方法的参数都变成agr0 ...
- java获取多个汉字的拼音首字母
本文属于http://java.chinaitlab.com/base/803353.html原创!!! public class PinYin2Abbreviation { // 简体中文的编码范围 ...
- 【转】如何使用Java、Servlet创建二维码
归功于智能手机,QR码逐渐成为主流,它们正变得越来越有用.从候车亭.产品包装.家装卖场.汽车到很多网站,都在自己的网页集成QR码,让人们快速找到它们.随着智能手机的用户量日益增长,二维码的使用正在呈指 ...
- Django之Model操作进阶篇
常用参数 null 数据库中字段是否可以为空 db_column 数据库中字段的列名 default 数据库中字段的默认值 primary_key 数据库中字段是否为主键 db_index 数据库中字 ...
- set源码之心得
C++的STL很强大,强大到我只愿慵懒地去使用而不知其所以然.直到李师问我,我的回答被李师否定,我方才意识到自己是多么地浅陋.希望自己有空抽时间把STL源码给研究一下,化为自己真正可以掌控的力量. s ...
- 线段树教做人系列(1)HDU4967 Handling the Past
题意:给你n组操作,分别为压栈,出栈,询问栈顶元素.每一组操作有一个时间戳,每次询问栈顶的元素的操作询问的是在他之前出现的操作,而且时间戳小于它的情况.题目中不会出现栈为空而且出栈的情况. 例如: p ...
- JS中的数组排序函数sort()
JavaScript实现多维数组.对象数组排序,其实用的就是原生的sort()方法,用于对数组的元素进行排序. sort() 方法用于对数组的元素进行排序.语法如下: arrayObject.sort ...
- 【摘自张宴的"实战:Nginx"】nginx模块开发
Nginx的模块不能够像Apache那样动态的加载,所以模块都要预先编译进Nginx的二进制可执行文件中. Nginx的模块有三种角色: 1. Handler(处理模块) 用于处理Http请求 ...