Search code examples
web-applicationspythoncherrypyweb.py

More efficient web framework than Web.py? Extremely Pythonic please!


I love webpy, it's really quite Pythonic but I don't like having to add the url mappings and create a class, typically with just 1 function inside it. I'm interested in minimising code typing and prototyping fast.

Does anyone have any up and coming suggestions such as Bobo, Nagare, Bottle, Flask, Denied, cherrypy for a lover of webpy's good things?

What makes it a good reason?

Also I don't mind missing out (strongly) text based templating systems, I use object oriented HTML generation. Code should be able to look something like this:

def addTask(task):
    db.tasks.append({'task':task,'done':False})
    return 'Task Added'
def listTasks():
    d = doc()
    d.body.Add(Ol(id='tasks'))
    for task in db.tasks:
        taskStatus = 'notDoneTask'
        if task.done: taskStatus = 'doneTask'
        d.body.tasks.Add(Li(task.task,Class=taskStatus))
    return d

Minimalistic CherryPy is looking like a strong contender at the moment. Will there be a last minute save by another?


Solution

  • Flask, Armin Ronacher's microframework built on top of Werkzeug, Jinja2 and good intentions (though you can use whichever templating engine you like, or none at all), does URL mapping very concisely.

    @app.route("/")
    def index():
      return """Hello, world. <a href="/thing/spam_eggs">Here's a thing.</a>"""
    
    @app.route("/thing/<id>")
    def show_thing(id):
      return "Now showing you thing %s."%id
      # (or:) return render_template('thing.html', id = id)
    

    Maybe that's what you're looking for?