djangosnippets.org: Latest snippets tagged with 'templatetag'https://djangosnippets.org/tags/templatetag/2019-03-04T06:53:58.732628-06:00spaceless_json
2019-03-04T06:53:58.732628-06:00dkoldyaevhttps://djangosnippets.org/snippets/10661/<p>Now you can format and compress json-data in django template</p>
Freely redistributableTweet embed template tag
2019-02-14T14:22:23.966059-06:00z3ke1rhttps://djangosnippets.org/snippets/10660/<p>Takes a tweet url, requests the json from Twitter oEmbed, parses the json for the html element and returns it to your template. The html returned is ready to go and will be shown as a tweet on your web page. This uses the Requests library for Python. A full …</p>
Freely redistributableTemplateTag to call a method / function WITH arguments
2018-01-05T08:18:56.516304-06:00michaeljtbrookshttps://djangosnippets.org/snippets/10633/<p><strong>Callmethod</strong> - TemplateTag to call a method on an object with arguments from within a template</p>
<pre><code>{% callmethod hotel.room_price_for_night night_date="2018-01-02" room_type=room_type_context_var %}
## equals ##
>>> hotel.room_price_for_night(night_date="2018-01-02", room_type="standard") #Assuming "standard" is the value of room_type_context_var
</code></pre>
<p>Django doesn't allow calling a method with arguments in the template to ensure good separation …</p>
Freely redistributableChange language in template using templatetag
2017-03-03T22:46:20.089334-06:00sainiprayhttps://djangosnippets.org/snippets/10607/<p>It will help for change URL in available languages in template</p>
Freely redistributableSimply Gravatar Templatetags
2017-01-10T19:38:30.271719-06:00agusmakmunhttps://djangosnippets.org/snippets/10600/<p>Simply Gravatar Templatetags, for example the name of this templatetag is: <code>templatetags/gravatar_tags.py</code>, this supported for Python2 or Python3. </p>
Freely redistributabletweetparser filter
2015-06-28T08:02:32.094796-05:00VincentLoyhttps://djangosnippets.org/snippets/10504/<p>Django Template Filter that parse a tweet in plain text and turn it with working Urls</p>
<p>Ceck it on <a href="https://github.com/VincentLoy/tweetparser-django-template-filter">GitHub</a></p>
<h1>tweetParser Django Template Filter</h1>
<p>this is a port of <a href="https://github.com/VincentLoy/tweetParser.js">tweetParser.js</a> to work as a Django template filter</p>
<h2>How does it work ?</h2>
<p>Once installed, just :
<code><p>{{ your_tweet|tweetparser }}</p></code></p>
<h2>Installation …</h2>
Freely redistributableget_querystring template tag
2015-02-09T09:18:23.499159-06:00skamhttps://djangosnippets.org/snippets/10463/<p>A Django Template tag used to construct urls with current querystring parameters. This is based on some code that I've written some years ago. Enjoy.</p>
Freely redistributableInherit the standard url tag to include domain name
2013-12-22T15:27:52.497281-06:00atodorov-otbhttps://djangosnippets.org/snippets/3013/<p>This module extends the standard `url' template tag in Django and adds support for fully qualified domain name URLs. It also can be extended with simple URL load balancing techniques if desired.</p>
<p>See my blog for the background story:
<a href="http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/">http://atodorov.org/blog/2013/12/22/django-template-tag-inheritance-howto/</a></p>
Freely redistributableCreate a random integer in a template
2013-08-23T04:40:29.542756-05:00bartTChttps://djangosnippets.org/snippets/2984/<p>Create a random integer with given length.</p>
<ul>
<li>For a length of 3 it will be between 100 and 999.</li>
<li>For a length of 4 it will be between 1000 and 9999.</li>
</ul>
<p>Use it in a template like:</p>
<pre><code>{% random_number as my_id %}
The id is {{ my_id }}
</code></pre>
Freely redistributableRetrieve human-readable value from choices tuple or value from dict
2013-02-07T11:46:49.526971-06:00JoeLinuxhttps://djangosnippets.org/snippets/2890/<p>Will help you retrieve the value from a dictionary with a supplied key, or the human-readable value from a choices tuple. Works as follows:</p>
<p>To retrieve the value of a dict:
<code>{{ crime_rates_dict|getval:"Chicago" }}</code> <-- will return value of <code>crime_rates_dict["Chicago"]</code></p>
<pre><code>To retrieve the human-readable value from a choices tuple:
`{{ …</code></pre>
Freely redistributableAdd querystring parameters to path (template tag)
2013-01-23T11:39:45.767733-06:00spenoirhttps://djangosnippets.org/snippets/2882/<p><code><h3>Page: {{ page.number }} of {{ page.paginator.num_pages }}</h3>
{% if page.has_previous or page.has_next %}
<div>
{% if page.has_previous %}
<a href="{% url_add_query page=page.previous_page_number %}">{% endif %}&laquo;
Previous
{% if page.has_previous %}</a>{% endif %}
|
{% if page.has_next %}
<a href="{% url_add_query page=page.next_page_number %}">{% endif %}
Next &raquo;{% if page.has_next %}</a>{% …</code></p>
Freely redistributableRecursive template tag for Django with arguments
2012-12-17T04:53:30.752648-06:00hyperairhttps://djangosnippets.org/snippets/2864/<p>This template tag was inspired by http://djangosnippets.org/snippets/592/, but with improvements in the syntax it is used with to be more function-like, and avoiding the problem of conditional recursion as noted in http://djangosnippets.org/comments/cr/15/592/#c2472.</p>
<p>The syntax for using it can be seen in the docstring of the defrecurse() function. Additionally, a magic …</p>
Freely redistributablenbsp filter
2012-11-07T16:55:41.222139-06:00vitamonhttps://djangosnippets.org/snippets/2842/<p>Replaces usual spaces in string by non breaking spaces.
"some words" --> "some&nbsp;words"</p>
<p>Usage in template:
{% load nbsp %}
....
{{ user.full_name|nbsp }}</p>
Freely redistributableActive page class for selected menu items
2012-09-26T02:10:26.645215-05:00kunitokihttps://djangosnippets.org/snippets/2825/<p>Simple tag to check which page we are on, based on resolve: useful to add an 'active' css class in menu items that needs to be aware when they are selected.</p>
<p>Typical usage is like:</p>
<p><code><ul>
<li class="{% active request "myapp:myview1" %}">My View 1</li>
<li class="{% active request "myapp:myview2" %}">My …</code></p>
Freely redistributabletemplate filter to include protocol and domain in absolute urls
2012-07-04T15:50:48.638153-05:00czerhttps://djangosnippets.org/snippets/2783/<p>I created this template filter to be able to use get_absolute_url in an email template.</p>
<p>Save the code into /templatetags/navigation.py</p>
<p>Use like this:</p>
<pre><code>{% load navigation %}
{{ instance.get_absolute_url|siteabsoluteurl:request }}
</code></pre>
Freely redistributable