Search code examples
pythonmodel-view-controllerormseparation-of-concerns

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)

Solution

  • 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.