Symfony has very useful feature - view component, this is small action code and template tha开发者_如何学Pythont you could embed anywhere inside view template:
<?php include_component('news') ?>
for example in above code mews component executes query in db and display results as block on a site page.
http://www.symfony-project.org/book/1_0/07-Inside-the-View-Layer#Components
I need something similar for Django to prepare and display login form in each view template.
We can call this a "widget" probably.
I think you're looking for Django's template tags feature. Template tags can make database calls, render partial templates, or do pretty much anything else you need them to do. Your example, as a template tag, might look something like this in your templates:
{% include_component 'news' %}
精彩评论