比 Web.py 更高效的 Web 框架?请非常Pythonic!

发布于 2024-09-04 05:07:41 字数 684 浏览 5 评论 0原文

我喜欢 webpy,它确实非常 Pythonic,但我不喜欢必须添加 url 映射并创建一个类,通常其中只有 1 个函数。 我对快速减少代码输入和原型设计感兴趣。

对于 webpy 的爱好者来说,有没有人有任何即将推出的建议,例如 Bobo、Nagare、Bottle、Flask、Denied、cherrypy?

是什么让它成为一个很好的理由?

另外,我不介意错过(强烈)基于文本的模板系统,我使用面向对象的 HTML 生成。代码应该看起来像这样:

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

简约的 CherryPy 目前看起来是一个强有力的竞争者。会有其他人在最后一刻做出拯救吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

感性不性感 2024-09-11 05:07:41

Flask,Armin Ronacher 的微框架构建在 Werkzeug、Jinja2 和良好的意图之上(尽管您可以使用任何模板引擎)你喜欢,或者根本不喜欢),URL 映射非常简洁。

@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)

也许这就是您正在寻找的?

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?

与风相奔跑 2024-09-11 05:07:41

CherryPy 允许您在树中连接处理程序而不是正则表达式。 web.py 可能会这样写:

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

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

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

等效的 CherryPy 是:

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

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

您甚至可以在 CherryPy 中完全省去类:

def delete(id): ...
def index(): ...
index.del = delete

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
川水往事 2024-09-11 05:07:41

我是 webpy 的用户。最近,我发现了 django,我认为它很棒。您只需专注于业务逻辑,框架就会为您完成大部分工作。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文