views:

661

answers:

3

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?

+3  A: 

CherryPy allows you to hook up handlers in a tree instead of regexes. Where web.py might write:

urls = (
    '/', 'Index',
    '/del/(\d+)', 'Delete'
)

class Index:
    def GET(self): ...

class Delete:
    def POST(self, id): ...

The equivalent CherryPy would be:

class Delete:
    def POST(self, id): ....

class Index:
    del = Delete()
    def GET(self): ...

You can even dispense with classes entirely in CherryPy:

def delete(id): ...
def index(): ...
index.del = delete
fumanchu
Thanks fumanchu, I especially like the classless example.I added an example to the question too.
Luke Stanley
+2  A: 

I was a user of webpy. And lately, I have found django, and I think that it is great. You can just focus on your business logic and the framework will do most things for you.

xiao
I'm strictly looking for more lightweight options. If Django's MVC system was as lightweight as fumanchu's non-MVC example, it might be a contendener. I'm well aware of Django, and looking to go beyond it, so less stuff has to fit in my head to prototype and actually develop. Simplicity and mix and match are probably key here. I'm looking for the minimum amount of keystrokes required.
Luke Stanley
Nagare, for example may be much closer than Django though it may not be as mix and match as Cherrypy. http://www.nagare.org
Luke Stanley
With Django, you can dispense with the models and templates, and simply have the views which are mapped to with a URLConf. Django CAN be very lightweight with respect to the code you need to write, while providing a whole lot of helper methods and classes to further minify the code.
Josh Smeaton
Sure you could, but why?
Luke Stanley
+2  A: 

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?

AKX
Thanks. That's a little less text duplication than with webpy but I want to do better. I added an example to the question.
Luke Stanley