IndexError when trying to print a list of routes
Author: oz123Created Feb 25, 2018Updated Sep 3, 2026
I have a small application divided into two files:
views.py and api.py, when developing I run a local server and I wanted to see a list of all routes.
from app.views import app as home_app
from app.api import app as api_app
main_app = bottle.Bottle()
@main_app.route('/static/<filepath:path>')
def server_static(filepath):
return bottle.static_file(filepath, root='static')
main_app.merge(home_app.routes)
main_app.mount("/api/", api_app)
print("DEBUG %s:" % main_app.routes) This results in the following error:
Traceback (most recent call last):
File "./manage.py", line 93, in <module>
args.func(args)
File "./manage.py", line 62, in serve
print("DEBUG %s:" % main_app.routes)
File "/home/oznt/Software/tiny-cms/tiny/bottle.py", line 616, in __repr__
cb = self.get_undecorated_callback()
File "/home/oznt/Software/tiny-cms/tiny/bottle.py", line 598, in get_undecorated_callback
func = func[0]
IndexError: list index out of rangeIf I exclude the API application (e.g. I don't mount it) I don't see the error.
The solution is pretty easy:
@@ -593,7 +593,9 @@ class Route(object):
# pick first FunctionType instance from multiple arguments
func = filter(lambda x: isinstance(x, FunctionType),
map(lambda x: x.cell_contents, attributes))
- func = list(func)[0] # py3 support
+ func = list(func) # py3 support
+ if len(func) > 0:
+ func = func[0]Would you like to receive a PR for this?
Source: bottlepy/bottle