Is passing ORM entities into templates acceptable in MVC pattern frameworks?
Is passing ORM entities directly into templates acceptable?
In a hypothetical python framework is this worse
def fetch开发者_运维问答_widgets:
widgets = widget.fetch("price < 50")
render_template('widget.html', widgets=widgets)
than this?
def fetch_widgets:
widgets = [(w.name, w.price) for w in widget.fetch("price < 50")]
render_template('widget.html', widgets=widgets)
If the template engine is only capable of retrieving models, then sure. It's when templates are used to manipulate models that the walls break down.
精彩评论