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
#1
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:


Error:
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?!
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  show csv file in flask template.html rr28rizal 7 22,955 Nov-09-2020, 01:32 PM
Last Post: humanz
  Python3 + BeautifulSoup4 + lxml (HTML -> CSV) - How to loop to next HTML/new CSV Row BrandonKastning 0 443 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  How to POST html data to be handled by a route endpoint nikos 1 546 Mar-07-2020, 03:14 PM
Last Post: nikos
  Why use HTML in Django Template ift38375 2 625 Dec-09-2019, 02:28 AM
Last Post: snippsat
  Problem with arguments in route function. darktitan 2 578 Aug-26-2019, 04:55 PM
Last Post: snippsat
  Problem enabling http auth in a route nikos 2 836 Mar-02-2019, 01:13 PM
Last Post: nikos
  Issue with bottle-pymysql nikos 13 1,335 Feb-23-2019, 11:15 AM
Last Post: nikos
  How to access routes using Bottle Framework nikos 5 1,295 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 1,754 Jun-11-2018, 06:04 AM
Last Post: bountyhuntr
  please explain Bottle runtime log Kebap 4 3,830 Sep-22-2016, 05:40 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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