生成具有utf-8值的链接,并将其传递到Flask路线

时间:2018-09-30 10:12:47

标签: python-3.x flask wsgi

我如何确保以下html url链接将以ALTER USER 'root'@'localhost' IDENTIFIED WITH mysql_native_password BY 'YOUR_MYSQL_PASSWORD'编码返回自身?

Location,S1,S2,S3,S4,C1,C2,TS3
PC_recapped,7.31,7.46,12.17,10.77,6.59,15.94,14.97
PC_infested,3.20,2.63,11.30,5.72,0.00,0.00,16.77
PC_recapped_and_infested,85.71,83.33,30.77,82.35,0.00,0.00,25.00
PC_normal_mites,85.71,100.00,69.23,76.47,0.00,0.00,39.29

现在,尽管从Flask中以utf-8检索文件名的值,但它也没有以<meta http-equiv="REFRESH" content="5; URL=http://superhost.gr/files/download?filename={{ filename }}"> 的形式形成UR​​L链接。

这是我获取此值并尝试使用它来下载文件的方式。

utf-8

我正在尝试在Apache / WSGI mod下生成与Jinja2 / Flask的链接。

也许是mod_wsgi下的Apache导致了此问题?!

我在浏览器中看到的错误是:

utf-8

根据Chrome的开发者工具/网络标签为具有混合文件名(希腊语和英语)的测试文件生成的链接为:

http://superhost.gr/files/download?filename=%CE%94%CE%B7%CE%BC%CE%B9%CE%BF%CF%85%CF%81%CE%B3%CE%AF%CE%B1%20Win10%20Bootable%20Flash%20Disks.txt

1 个答案:

答案 0 :(得分:1)

我正在尝试重现您的问题,但我认为您应该提供更多信息。

我尝试了以下设置,Νικόλαος Βέργος.pdf正确返回了名为/redirect/的文件。

app.py

from flask import render_template
from flask import Flask
from flask import request, send_from_directory
app = Flask(__name__)

@app.route('/')
def home():
    filename='Νικόλαος Βέργος.pdf'
    return render_template('home.html', filename=filename)

@app.route('/redirect/')
def redirect():
    if request.args:
        filename = request.args.get('filename')
        filepath = '/static/files/'
        return send_from_directory(filepath, filename, as_attachment=True)

templates / home.html

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta http-equiv="REFRESH" content="5; URL=http://127.0.0.1:5000/redirect/?filename={{ filename }}">
    <title>title</title>
  </head>
  <body>
  </body>
</html>