Skip to content

Instantly share code, notes, and snippets.

@skazhy
Created April 5, 2012 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skazhy/2309339 to your computer and use it in GitHub Desktop.
Save skazhy/2309339 to your computer and use it in GitHub Desktop.
Django templatetags example
ul>
{% for p in posts %}
<li><a href="{{ a.url }}">{{ a.title }}</a>
{% endfor %}
</ul>
# This should go in app/templatetags/app_tags.py
from django.template import Library
from app.models import Post
register = Library()
@register.inclusion_tag('app/_latest_posts.html')
def latest_posts():
posts = Post.objects.order_by('-date')[:6]
return locals()
{% load app_tags %}
// Lots of HTML
<div>
{% latest_posts %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment