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 8 34,532 Apr-12-2021, 09:24 AM
Last Post: adamabusamra
  HTML multi select HTML listbox with Flask/Python rfeyer 0 4,536 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 2,329 Mar-22-2020, 06:10 AM
Last Post: BrandonKastning
  How to POST html data to be handled by a route endpoint nikos 1 2,350 Mar-07-2020, 03:14 PM
Last Post: nikos
  Why use HTML in Django Template ift38375 2 2,774 Dec-09-2019, 02:28 AM
Last Post: snippsat
  Problem with arguments in route function. darktitan 2 2,960 Aug-26-2019, 04:55 PM
Last Post: snippsat
  Problem enabling http auth in a route nikos 2 2,747 Mar-02-2019, 01:13 PM
Last Post: nikos
  Issue with bottle-pymysql nikos 13 5,360 Feb-23-2019, 11:15 AM
Last Post: nikos
  How to access routes using Bottle Framework nikos 5 4,205 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 3,605 Jun-11-2018, 06:04 AM
Last Post: bountyhuntr

Forum Jump:

User Panel Messages

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