djangosnippets.org: Latest snippets tagged with 'template'http://djangosnippets.org/tags/template/2018-01-05T08:18:56.516304-06:00TemplateTag to call a method / function WITH arguments
2018-01-05T08:18:56.516304-06:00michaeljtbrookshttp://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:00sainiprayhttp://djangosnippets.org/snippets/10607/<p>It will help for change URL in available languages in template</p>
Freely redistributableGet template filename from within the template
2017-02-08T22:09:19.604128-06:00harikvpyhttp://djangosnippets.org/snippets/10605/<p>Two simple tags to extract the template filename from within a template.</p>
Freely redistributableRelative paths for Django template tags 'extends' and 'include'.
2016-03-17T07:00:40.022829-05:00vb64http://djangosnippets.org/snippets/10558/<p><a href="http://stackoverflow.com/questions/671369/django-specifying-a-base-template-by-directory">The problem</a>: {% extends "./../base.html" %} won't work with extends.</p>
<p>It causes a lot of inconvenience, if you have an extensive hierarchy of django templates.
This library allows relative paths in argument of 'extends' and 'include' template tags. Relative path must start from "./"</p>
<p>Just write in your templates …</p>
Freely redistributableReusable form template with generic view
2015-12-02T08:02:40.154798-06:00roldandvghttp://djangosnippets.org/snippets/10541/<p>If you require lots of forms in your project and do not want to be creating an extended template for each one I propose this solution.</p>
<p>Classes in the html correspond to bootstrap, you can work without them if you do not use bootstrap.</p>
Freely redistributablelist django template's inheritance hierarchy
2015-09-28T21:11:43.439736-05:00wonderbeyondhttp://djangosnippets.org/snippets/10531/<p>list django template's inheritance hierarchy</p>
<p>Example:</p>
<pre><code> DJANGO_SETTINGS_MODULE=mysite.settings django-templates-tree.py base.html
</code></pre>
Freely redistributableDatetime adjuster for Django Templates
2015-07-22T08:54:23.899048-05:00McAnixhttp://djangosnippets.org/snippets/10516/<p>The filter is <strong>specific to datetime objects</strong> and no allowance has been made to convert strings or epoch times. Also <strong>no type checking</strong> is performed so misuse will result in an error.</p>
<p>To use include the above snippet in a file called templatetags/customfilters.py or append to existing filters file then …</p>
Freely redistributable Load template from specific app
2015-05-22T13:05:10.797145-05:00fabiomontefuscolohttp://djangosnippets.org/snippets/10489/<p>It's an update of snippet <a href="https://djangosnippets.org/snippets/1376/">https://djangosnippets.org/snippets/1376/</a> to work with Django 1.8. With this piece of code, you can override admin templates without copy or symlink files. Just write your template and extend the target.</p>
Freely redistributableCancel URL Mixin
2015-05-20T04:24:54.190419-05:00halfnibblehttp://djangosnippets.org/snippets/10488/<p><strong>CancelMixin</strong></p>
<p>A simple mixin to use with <code>generic.CreateView</code> and <code>generic.UpdateView</code> view form templates to effortlessly implement a "Cancel" button. </p>
<p>This smart mixin will add a URL to your context, <code>{{ cancel_url }}</code>, that can be used as a cancel link in your form template. If no referrer URL is …</p>
Freely redistributableSimple class to organize email templates
2015-04-13T20:40:28.002317-05:00jeanhttp://djangosnippets.org/snippets/10479/<p><strong>Provides pattern to organize and send your email messages.</strong></p>
Freely redistributableget_querystring template tag
2015-02-09T09:18:23.499159-06:00skamhttp://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 redistributabledjango form template with bootstrap
2015-01-25T06:42:20.594179-06:00youyongsonghttp://djangosnippets.org/snippets/10458/<h2>required</h2>
<ul>
<li><code>{% load trans%}</code>before using this snippets</li>
<li>Add this <a href="https://djangosnippets.org/snippets/2253/">template filter</a> to your custom templatetags and load it before using this snippets</li>
<li>Bootstrap framework</li>
</ul>
Freely redistributableDjango forms add placeholder from help text template tag
2014-05-17T11:14:13.857311-05:00Ahmad.Dukhanhttp://djangosnippets.org/snippets/3050/<p>This snippet will change the field to include the placeholder in the field using the help_text attribute from the model or the form</p>
Freely redistributableTemplate tag and filter for displaying number of years since
2014-03-22T04:43:20.965085-05:00tgandorhttp://djangosnippets.org/snippets/3037/<p>Because {% now "Y"|add:"-2005" %} - etc. doesn't work, you can use the above in your template like:</p>
<p>We have {{ 2000|since }} years of experience.</p>
<p>or:</p>
<p>Serving our customers with passion for more than {% years_since 2005 %} years.</p>
Freely redistributableDisplay values from a bound (submitted) form
2014-03-13T05:20:42.339965-05:00masidahttp://djangosnippets.org/snippets/3036/<p>Function that takes a bound form (submitted form) and returns a list of pairs of field label and user chosen value.</p>
<p>It takes care of:</p>
<ol>
<li>fields that are not filled out</li>
<li>if you want to exclude some fields from the final list</li>
<li>ChoiceField (select or radio button)</li>
<li>MultipleChoiceField (multi-select or …</li></ol>
Freely redistributable