开发者

Is using template tags to pull data a violation of separation of concerns?

I'm wondering if the django generic flatblocks app is a violation of the separation of concerns principle.

For those of you who do not know the app, it is pulling data based on a slug or id and a model type.

For example:

{% gblock "about" for "cms.FlatPageWithsummary" into "about" %}

On o开发者_运维百科ne hand, it marks where the content should appear so it makes sense from the designer's point of view but on the other hand it shouldn't be the template's responsibility to fetch data.

What should I do? Should I pass it through the request context? Now I am facing another situation where I need to pull my latest posts and display them.

Where's the line here?

Because again, the designer is able to mark and implement this feature only by using my supplied template tag, but on the other hand, I am fetching data from a template which seems kinda wrong.


What if it is? These "principles" are there to make our lives as developers and users easier. If the easiest and cleanest way to do something breaks that principle, we should feel free to do so, as long as the quality of the code doesn't suffer. It's not like there's a moral reason to observe separation of concerns at all costs.

And, don't forget, there are other principles to follow as well. Accepting for the sake of argument that this does break separation of concerns, it still most definitely follows DRY. If those principles are in conflict, you should choose which one to follow.


django.contrib.comments too fetches data from the DB in a templatetag. If you want to make your apps reusable, then this is a common pattern.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜