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 ...
随机推荐
- c#的日志插件NLog基本使用
本文介绍c#的日志插件NLog 安装插件 创建logger 日志级别 书写日志信息 配置 包装器 布局 安装插件 直接下载插件包 Install-Package NLog.Config 创建logge ...
- springmvc 在页面跳转之后 引入文件的路径前面加上了 controller 的映射名
转自:https://zhidao.baidu.com/question/2140453086362943788.html 应该是没有前面的/user的 前端用的是jsp吗,如果是在路径前加${pag ...
- 监控和安全运维 1.3 cacti增加客户端监控
二. 安装客户端(增加一个linux服务器) 1.在客户端上 安装snmp yum install -y net-snmp 2. 修改snmpd.conf vim /etc/snmp/snmpd.co ...
- Shell编程进阶 1.7 case选择
逻辑判断的格式 vim case.sh #!/bin/bash read -p "please input a number:" n m=$[$n%] case $m in ) e ...
- 推荐一款GIF录制工具
LICEcap 是一款屏幕录制工具,支持导出 GIF 动画图片格式,轻量级.使用简单,录制过程中可以随意改变录屏范围 下载 http://www.cockos.com/licecap/
- hibernate学习笔记(4)表单操作
User.hbm.xml的表单配置: ①主键 <id name="id" type="java.lang.Integer"> <column ...
- Mediaplayer
Mediaplayer报错 prepareAsync called in state 1 是因为在setDataSource之前调用了prepare.因为setDataSource放到了线程里 ...
- ListView的ScrollListener
@Override public void onScrollStateChanged(AbsListView paramAbsListView, int paramInt) { //当屏幕停止滚动时为 ...
- 第4章 springboot热部署 4-1 SpringBoot 使用devtools进行热部署
/imooc-springboot-starter/src/main/resources/application.properties #关闭缓存, 即时刷新 #spring.freemarker.c ...
- win10右击windows键没有反应解决方案(1707版本)
按Win+R打开运行,输入“regedit”打开注册表编辑器. 2.在“HKEY_CLASSES_ROOT”主键下找到“linkfile”或者".lnkfile"字符串值项,在右侧 ...