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

AWS GenAI LIVE image

How is generative AI increasing efficiency?

Join AWS GenAI LIVE! to find out how gen AI is reshaping productivity, streamlining processes, and driving innovation.

Learn more

Top comments (0)

AWS GenAI LIVE image

Real challenges. Real solutions. Real talk.

From technical discussions to philosophical debates, AWS and AWS Partners examine the impact and evolution of gen AI.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay