烧瓶send_static_file-找不到错误

时间:2018-08-02 08:40:44

标签: python flask

试图使其与我以前的问题serve static files上标记的重复问题一起使用

但是我只能得到这个:

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文件的运行目录中创建了文件output.txt,并且我的静态路径设置为”,因此它应该使用正在运行的程序的根目录-或不?

我想要做的是:在计算机上下载该文件,然后按按钮执行WilmaGetLogs-不在服务器上

1 个答案:

答案 0 :(得分:0)

我现在设法用return send_from_directory("./", "output.txt", as_attachment=True)发送文件-仍然不知道为什么send_static_file不起作用,但是通过send_from_directory我可以将其发送到单击网页上的按钮并获得响应自动下载output.txt文件