DEV Community

Anton Shcherbatov
Anton Shcherbatov

Posted on

Bottle+Sqlite

A few more words about Bottle. After enabling a sqlite extension, you can easily include a specified keyword as a view argument. Like:

app = bottle.Bottle()
db_plugin = bottle_sqlite.Plugin(dbfile='./test.db', keyword="db")
app.install(db_plugin)

@app.route("/")
def main(db):
    ....
Enter fullscreen mode Exit fullscreen mode

It works perfect... Until you decide to show the view for authorized users only. And this

@bottle.auth_basic()
def save_post(db):
    ...
Enter fullscreen mode Exit fullscreen mode

will cause

TypeError("main() missing 1 required positional argument: 'db'")
Enter fullscreen mode Exit fullscreen mode

This is a known issue, which still wasn't solved on the plugin level. So, again workarounds

The only change here is:

params = inspect.signature(_callback).parameters
if keyword not in params:
    return callback
Enter fullscreen mode Exit fullscreen mode

instead of

argspec = inspect.getargspec(_callback)
Enter fullscreen mode Exit fullscreen mode

Top comments (0)