python - 烧瓶 send_static_file - 未找到错误
问题描述
试图让它与在我以前的问题上标记的重复问题一起工作,提供静态文件
但我只得到这个:
Not Found
The requested URL was not found on the server. If you entered the URL
manually please check your spelling and try again.
这是我的代码:
app = Flask(__name__, static_url_path='')
@app.route('/WilmaGetLogs/<name>"')
def WilmaGetLogs(name):
path="cat /var/log/messages"
tempStr=''
HOST = name
user = "root"
password = "asdf"
print('Test')
tn = telnetlib.Telnet(HOST, timeout=5)
tn.read_until(b"login: ")
time.sleep(1)
tn.write(user.encode('ascii') + b"\n")
tn.read_until(b'Password: ')
time.sleep(1)
tn.write(password.encode('ascii') + b"\n")
time.sleep(2)
tn.write(path.encode('ascii') + b"\n")
tn.write(b"exit\n")
tempStr=tn.read_all().decode('ascii')
text_file=open("output.txt","w")
text_file.write(tempStr)
text_file.close()
return app.send_static_file("output.txt")
文件 output.txt 在 .py 文件正在运行的目录中创建,并且我的静态路径设置为 '' 所以它应该使用正在运行的程序的根目录 - 或者不?
我想要做的是:在计算机上下载文件,我按下按钮执行 WilmaGetLogs - 而不是在服务器上
解决方案
我现在设法发送文件return send_from_directory("./", "output.txt", as_attachment=True)
- 仍然不知道为什么 send_static_file 不起作用,但使用 send_from_directory 我能够将它发送到单击网页上的按钮并获得自动文件下载输出的客户端作为响应。文本
推荐阅读
- devextreme - 当 HScroll 滚动超过列边框时,固定列文本与非固定列文本重叠
- mysql - 如何从 TADOQuery 获取最后一个惰性 ID?
- sql - 如果执行在列中具有相同值的相同操作,我应该使用什么 sql 查询
- reactjs - 从手表自动重载反应中忽略文件夹
- arrays - 收到警告:从指针转换为不同大小的整数,同时将字符串转换为整数数组并打印不相关的数字
- primefaces - CommandButton onclick="this.form.target = '_blank'" ajax="false" 在 Dialog Primefaces 10 中不起作用
- python - 如何创建动态路由以检索表
- angular - 是否有任何选项可以直接将数据传递给 SVGImageElement?
- javascript - 将单个数组中的多个对象“转换”为“一个数组一个对象”
- r - 使用带有 gridExtra 的拼凑来保存跨多个页面的图的问题