1 回答

TA贡献1895条经验 获得超3个赞
所以你需要用你的python代码打开文件夹,提取正确的图片并发送给你的用户?
你可以这样做
file = "d:\genealogie\documenten\your_file_name" #you may consider a path library so you can do this in windows or Linux
os.open(file) #you should really use a image library here. open is just a placeholder
换句话说,您想在代码(函数、类等)中打开图像,然后对图像执行任何您需要执行的操作。例如将其返回给用户。
我个人会尝试使用这样的东西:
from flask import send_file
file = "d:\genealogie\documenten\your_file_name" #you may consider a path library so you can do this in windows or Linux
return send_file(file, mimetype='image/jpg') #in case of jpg image, you may opt to not use the mimetype
你不能这样做
documenten = "d:\genealogie\documenten"
app = Flask(__name__, static_url_path='documenten')
但为什么?基本上static_url_path是用户输入浏览器的网址。这与您在服务器上的文件夹结构无关。哎呀,你甚至不需要在你的服务器上有文件夹。
您的互联网呈现的结构不必与您的文件系统的结构相关。基本上,这是两个完全不同的世界在这里碰撞。
URL用于分层构建网络,主要应对组织结构(域、子域)。另一方面,文件服务器可以以多种方式构建。通常,您希望表示文件的性质和/或文件的年龄。
顺便说一句,该mkdir命令会创建文件夹,但您已经拥有了一些。
添加回答
举报