Passing a query value from a Bottle html template

2019-08-17 18:58发布

I want to pass a query from a bottle html template to a route function which i'm trying to perform as:

<meta http-equiv="REFRESH" content="5; URL=http://superhost.gr/files/download?file={{ filename }}">

The route is declared as follows:

@app.route( '/download', method=['GET', 'POST'] )
def file():

    # Prepare selected file for download...
    if request.query:
        filename = request.query.get('file')
        filepath = '/static/files/'

        return static_file( filename, root=filepath, download=True )

If the filename is in latin-iso all is going fine, but IF the value of the param 'file' contain Greek letters i' getting an exception:

UnicodeEncodeError('ascii', '/static/files/Î\x92ιογÏ\x81αÏ\x86ικÏ\x8c - Î\x9dίκοÏ\x82.docx', 14, 34, 'ordinal not in range(128)')

So, when i'm passing the value from the template to the route, i need to ensure that tha parameter value will be passed with 'utf-8' encoding much like as with the same manner as when it comes to posting forms, otherwise i'm getting a unicode error.

<form method="POST" enctype="multipart/form-data" action="/mailform">

How can i do that?

0条回答
登录 后发表回答