bottlepy / bottle

bottle.py is a fast and simple micro-framework for python web-applications.
http://bottlepy.org/
MIT License
8.33k stars 1.46k forks source link

regex in route isn't working as expected #1340

Closed johncblacker closed 3 years ago

johncblacker commented 3 years ago

I'm using bottle v0.12.19 on rPi and have the following routes: @route('stream/d') @route('stream/<val:re:d\d*>'

When the app starts, it sends an image with 'stream/d' as the source and I get a flash of image on the screen, then it proceeds on to a imageRefresh javascript function that extracts the first part of the http data (http://192.168.0.18:8080) and appends to it a /d and a Date.time() value. So this request would look like: "GET /stream/d1234567654321" and that results in a 404 error at the browser - which I believe means it's not matching the second route. I need some guidance on this as to whether it's something I'm doing wrong or is there a bug in the bottle code.

ifduyue commented 3 years ago

According to http://bottlepy.org/docs/dev/routing.html#legacy-syntax image

This works:

@route('/stream/d')
@route('/stream/<val:re:d\d*>')
#      ^ notice the leading /
defnull commented 3 years ago

Yes, stream/val:re:d\d* is does not make any sense. The old syntax would be /stream/:val#d\d*#. The 'new' Syntax would be /stream/<val:re:d\d*>. In any case, don't forget the leading slash.