开发者社区 问答 正文

在MVC模式框架中是否可以将ORM实体传递到模板中?

将ORM实体直接传递到模板中是否可以接受?

在一个假设的python框架中,情况更糟

def fetch_widgets:
    widgets = widget.fetch("price < 50")
    render_template('widget.html', widgets=widgets)

比这个?

def fetch_widgets:
    widgets = [(w.name, w.price) for w in widget.fetch("price < 50")]
    render_template('widget.html', widgets=widgets)

展开
收起
祖安文状元 2020-02-23 16:19:45 806 分享 版权
1 条回答
写回答
取消 提交回答
  • 如果模板引擎仅能够检索模型,请确定。正是在使用模板来操纵模型时,墙才崩溃。

    2020-02-23 16:19:49
    赞同 展开评论