Marker using a path with a leading slash

I am trying to get Flask using a simple route with a path converter:

@api.route('/records/<hostname>/<metric>/<path:context>') 

It works unless the "path" in the URL uses a leading slash. In this case, I get 404. I understand the error, but what I do not understand is that there is no workaround in the documentation or anywhere on the Internet how to fix this. I feel like I'm the first to try to do this basic thing.

Is there a way to make this work with a meaningful URL? For example, a query like this:

http://localhost:5000/api/records/localhost/disks.free//dev/disk0s2 
+4
source share
1 answer

PathConverter URL ; , ​​ .

PathConverter :

regex = '[^/].*?'

, /.

; , URL-, URL- %2F , URL- WSGI.

:

from werkzeug.routing import PathConverter

class EverythingConverter(PathConverter):
    regex = '.*?'

app.url_map.converters['everything'] = EverythingConverter

@api.route('/records/<hostname>/<metric>/<everything:context>') 

Flask app .

+9

Source: https://habr.com/ru/post/1542961/


All Articles