Created
February 11, 2016 16:41
-
-
Save rupakraj/2c3923f2b4c47f069afe to your computer and use it in GitHub Desktop.
Handy tags and blocks for Django. Useful for the programmer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# DJango Template Tags Cheat Sheet | |
## Inheritance and Inclusion | |
{% extends "base.html "%} | |
{% block content %} ... {% endblock %} or {% block content %} ... {% endblock content %} | |
{% include "foo/bar.html" %} | |
{% ssi /home/html/ljworld.com/includes/right_generic.html %} | |
## Filters and Tags | |
{% load <tag_or_filter_lib> %} | |
{% filter <filter>[|<filter>...] %} | |
## Control | |
{% for o in some_list %} ... {% endfor %} | |
{% ifchanged %} (Content to check status of) {% endifchanged %} | |
{% if <var> %} ... {% endif %} | |
{% if[not]equal user.id comment.user_id %} ... [{% else %}] ... {% endif[not]equal %} | |
{% cycle row1,row2 %} | |
{% cycle row1,row2 as rowcolors %} {% cycle rowcolors %} | |
{% firstof var1 var2 var3 %} | |
{% regroup people by gender as grouped %} ... {% for group in grouped %} {{ group.grouper }} ... | |
## Others | |
{% templatetag (openblock|closeblock|openvariable|closevariable|openbrace|closebrace) %} | |
{% widthratio this_value max_value 100 %} | |
It is {% now "jS F Y H:i" %} | |
{% spaceless %} ... {% endspaceless %} | |
See also [templates for designers](http://www.djangoproject.com/documentation/templates/) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment