开发者

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

开发者 https://www.devze.com 2023-01-02 07:03 出处:网络
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references,or expertise, but this question will likely solicit debate, a
As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 10 years ago.

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 obje开发者_如何学Cct 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?


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?


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号