Friday, 13 September 2013

500 error when binding index and other routes to a single callback in Bottle

500 error when binding index and other routes to a single callback in Bottle

Following this tutorial:
http://bottlepy.org/docs/dev/tutorial.html#request-routing
It shows the example:
@route('/')
@route('/hello/<name>')
def greet(name='Stranger'):
return template('Hello {{name}}, how are you?', name=name)
And states:
This example demonstrates two things: You can bind more than one route to
a single callback, and you can add wildcards to URLs and access them via
keyword arguments.
I'm trying to test this with the following code but I am getting a 500
error when accessing the index eg /.
import bottle
import pymongo
custom = bottle
@custom.route('/')
@custom.route('/hello/<name>')
@custom.view('page2.tpl')
def index(name):
# code
bottle.run(host='localhost', port=8082)
The error only seems to occur when accessing the site's index, eg /.
The index does not work in the following example, but the other two routes
do.
import bottle
import pymongo
custom = bottle
@custom.route('/') # this doesn't work
@custom.route('/milo/<name>') # this works
@custom.route('/hello/<name>') # this works
@custom.view('page2.tpl')
def index(name):
# code
bottle.run(host='localhost', port=8082)

No comments:

Post a Comment