djangosnippets.org: Latest snippets tagged with 'string'http://djangosnippets.org/tags/string/2016-09-01T21:40:45.890903-05:00Custom template filter remove words at end of a string
2016-09-01T21:40:45.890903-05:00quevon24http://djangosnippets.org/snippets/10585/<p>Filter to remove words at the end of a string</p>
<p>Example:</p>
<p>Myvar: "My name is Arthur and django si awesome"</p>
<p>{{myvar|wordend:4}}</p>
<p>Output: "My name is Arthur"</p>
Freely redistributableCustom template filter remove words at beginning of a string
2016-09-01T21:35:35.866478-05:00quevon24http://djangosnippets.org/snippets/10584/<p>Filter to remove words at the beginning of a string</p>
<p>Example:</p>
<p>Myvar: "My name is Arthur and django si awesome"</p>
<p>{{myvar|wordremoveb:5}}</p>
<p>Output: "django is awesome"</p>
Freely redistributableFilter that adds a period at the end of a string
2013-01-15T14:59:11.240376-06:00Ztyxhttp://djangosnippets.org/snippets/2878/<p>Yeah, I know this is a very basic filter, but I thought I might as well share it with the world...</p>
Freely redistributableTrim the center of a string
2012-12-05T01:50:35.772198-06:00grillermohttp://djangosnippets.org/snippets/2857/<p>I had to build unique strings for a payment system and i wanted to make them kindof friendly so i generated them with usernames and datetimes(safe enough uniqueness in combo), some usernames are long and they break the limit of this payment system so i thought i should cut the …</p>
Freely redistributableConverts an integer or floating-point number or a string to a string containing the delimiter character (default comma) after every delimeter_count digits (by default 3 digits)
2012-03-14T16:02:38.243837-05:00pikhovkinhttp://djangosnippets.org/snippets/2716/<p>Converts an integer or floating-point number or a string to a string containing the delimiter character (default comma) after every delimeter_count digits (by default 3 digits)</p>
Freely redistributableformat_thousands
2011-06-28T14:56:49.198163-05:00cootetomhttp://djangosnippets.org/snippets/2473/<p>Template filter to format a number so that it's thousands are separated by commas. </p>
<p>{{ number|format_thousands }}</p>
Freely redistributableConvert String Uppercase and Lowercase
2011-04-15T01:57:08.192780-05:00oraculumhttp://djangosnippets.org/snippets/2416/<p>To convert string to lower case replace upper() for lower()</p>
Freely redistributableTruncate text to length up until the nearest space
2011-03-05T10:32:17.191274-06:00phektushttp://djangosnippets.org/snippets/2382/<p>This will truncate a long character based on the given length parameter. If the word is cut-off, it will return the string up until the next space. If there are no spaces in the next 5 characters, that should mean a very long word and we should truncate right away.
</p>
Freely redistributableParse datetime model field to string
2010-07-03T02:59:18.553331-05:00jzelezhttp://djangosnippets.org/snippets/2090/<p>Checks the type of the field (date / time / date-time) and returns corresponding value as a string.</p>
Freely redistributabletruncatestring filter
2009-03-06T02:23:48.734005-06:00piglettohttp://djangosnippets.org/snippets/1354/<p>Simple filter that truncates string to specific number of letters. Example usage in template:
<code>{{ myvariable|truncatestring:20 }}</code></p>
<p>if myvariable is "That is my long string", the result will be: "That is my long s...".</p>
<p>Put the code into templatetags/.</p>
Freely redistributableTemplate tags/filter for working with query strings
2008-01-18T13:13:44.470194-06:00gonzhttp://djangosnippets.org/snippets/553/<p>Some template tags/filter for working with query strings in templates.</p>
<p>Examples:</p>
<pre><code>{% load qstring %}
{% qstring %} # Prints current request's query string
{% qstring as current_qstring %} # Same but goes to context
{{ current_qstring|qstring_del:"key1" }} # Deletes all key1 values
{{ current_qstring|qstring_del:"key1&key2" }} # Deletes all key1 …</code></pre>
Freely redistributableSessions and authentication without cookies
2007-11-07T14:39:03.939817-06:00danfairshttp://djangosnippets.org/snippets/460/<p><a href="http://www.djangoproject.com/documentation/sessions/">The Session documentation</a> rightly warns of the dangers of putting a session ID into a query string. Sometimes, however, you have to do it - perhaps your client has mandated support for browsers with cookies disabled, or perhaps (as in my case) you're just dealing with a slightly broken client …</p>
Freely redistributableSlice filter
2007-03-06T14:52:47.258331-06:00sneeuhttp://djangosnippets.org/snippets/87/<p>Handy for things such as:
<code>{{ some_string|slice:","|join:";" }}</code></p>
Freely redistributableClient-side Django-style date & time string formatting
2007-03-06T07:01:27.959819-06:00robbiehttp://djangosnippets.org/snippets/84/<p>This is a reasonably straight forward port of functionality provided by the <code>django.utils.dateformat</code> module into a method extending JavaScript's Date object. Its intended use is to allow client-side dynamic content to share the same date & time string formatting as Django template markup. By using this in conjunction with a …</p>
Freely redistributable