这个部分任务该怎么写有能教一下嘛使用软件pyCharm。有代码演示嘛!
这个部分任务该怎么写有能教一下嘛使用软件pyCharm。有代码演示嘛!
flask框架和vue框架前后端的数据传输
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
3条回答 默认 最新
- CSDN专家-showbo 2021-11-12 16:32关注
不就是用flask搭建个web服务器显示flask项目下的图片路径吗。大概示例如下
app.pyfrom flask import Flask, request,render_template import json import os app = Flask(__name__, static_url_path='') @app.route('/') def index(): url=r"static/images/"#读取当前py文件下static/images目录下的图片文件 arr=[] for root,dir,files in os.walk(url): for f in files: if(f.lower().endswith(('.png', '.jpg', '.jpeg', '.gif'))): arr.append("/images/"+f) return render_template("index.html",files=arr) if __name__ == "__main__": app.run('0.0.0.0', port=8001,debug=True)
templates/index.html,注意在app.py下建立templates目录,将index.html放里面
<meta charset="utf-8" /> <style> img{display:inline-block;margin-right:10px;height:100px} a{text-decoration:none} </style> {% for f in files %} <a rhef="{{f}}" target="_blank"><img src="{{f}}" /></a> {% endfor %}
static/images这个路径放图片文件
最终效果
有帮助麻烦点下【采纳该答案】,谢谢~~有其他问题可以继续交流~本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报
悬赏问题
- ¥20 腾讯企业邮箱邮件可以恢复么
- ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
- ¥15 错误 LNK2001 无法解析的外部符号
- ¥50 安装pyaudiokits失败
- ¥15 计组这些题应该咋做呀
- ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
- ¥15 让node服务器有自动加载文件的功能
- ¥15 jmeter脚本回放有的是对的有的是错的
- ¥15 r语言蛋白组学相关问题
- ¥15 Python时间序列如何拟合疏系数模型