Python Forum
Passing a query value from a Bottle html template to a route with an encoding
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Passing a query value from a Bottle html template to a route with an encoding
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={{ 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?!

Possibly Related Threads…
Thread Author Replies Views Last Post
  show csv file in flask template.html rr28rizal 8 27,036 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
  HTML multi select HTML listbox with Flask/Python rfeyer 0 1,110 Mar-14-2021, 12:23 PM
Last Post: rfeyer
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 908 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  How to POST html data to be handled by a route endpoint nikos 1 1,021 Mar-07-2020, 03:14 PM
Last Post: nikos
  Why use HTML in Django Template ift38375 2 1,242 Dec-09-2019, 02:28 AM
Last Post: snippsat
  Problem with arguments in route function. darktitan 2 1,134 Aug-26-2019, 04:55 PM
Last Post: snippsat
  Problem enabling http auth in a route nikos 2 1,313 Mar-02-2019, 01:13 PM
Last Post: nikos
  Issue with bottle-pymysql nikos 13 2,350 Feb-23-2019, 11:15 AM
Last Post: nikos
  How to access routes using Bottle Framework nikos 5 1,991 Feb-13-2019, 11:43 PM
Last Post: nikos
  Django - Passing data from view for use client side with JavaScript in a template bountyhuntr 0 2,225 Jun-11-2018, 06:04 AM
Last Post: bountyhuntr

Forum Jump:

User Panel Messages

Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020