djangosnippets.org: Latest snippets tagged with 'html'https://djangosnippets.org/tags/html/2015-12-02T08:02:40.154798-06:00Reusable form template with generic view
2015-12-02T08:02:40.154798-06:00roldandvghttps://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 redistributableTemplate tag to render collections.Counter as an html table
2015-06-19T10:12:27.396198-05:00asfaltboyhttps://djangosnippets.org/snippets/10502/<p>Render a given instance of collections.Counter into a 2 column html table.</p>
<p>Optionally accepts <code>column_title</code> keyword argument which sets the table
key column header.</p>
<p>Usage:</p>
<pre><code>{% counter_table event_counter column_title='event type' %}
</code></pre>
<p>The above will render the a table from the <code>event_counter</code> variable with the first (key) column set to "event …</p>
Freely redistributablesplit in html template
2012-06-19T08:30:37.957645-05:00musluhttps://djangosnippets.org/snippets/2772/<p>Html içinde split ile kesme</p>
<p>Kesme işleminden sonra kaçıncı bloğun okunacağını düzeltebilme</p>
<p>{% kes request.path "/" 3 4 %}</p>
<p>gelenveri.split("/")[3:4]</p>
Freely redistributableDecode HTML Template Tag
2012-03-13T13:09:00.611115-05:00megamark16https://djangosnippets.org/snippets/2714/<p>This is useful if you have a string that is html encoded (i.e. "&lt;p&gt;Hello world!&lt;/p&gt;") and you want to do something more complex than just display it as html, such as using the striptags filter.</p>
Freely redistributableFilter change list by a date range
2012-02-05T23:50:34.056189-06:00arusenihttps://djangosnippets.org/snippets/2675/<p>The Django admin site has a feature to filter objects in change list by parameters supplied in the query string. Particularly, parameters such as date__gte and date__lte can be used.</p>
<p>This example is for filtering objects in change list by a date range (the date field is called expiration_date, but …</p>
Freely redistributableultralize
2011-08-24T14:54:31.949032-05:00catellarhttps://djangosnippets.org/snippets/2525/<p>This is a function based on django's urlize modified to show different media based on their url. It supports images, links, mp3/ogg links, youtube videos, vimeo videos and dailymotion videos.</p>
<p>I added a switch called mini to have two modes to show things in different places. When mini is activated …</p>
Freely redistributablefilter for extracting a number of paragraphs from any HTML code
2011-06-10T13:24:21.983594-05:00rafadevhttps://djangosnippets.org/snippets/2462/<p>From: <a href="http://incredibletimes.org">incredible times</a></p>
<p>With inspiration from: <a href="http://unethicalblogger.com/2008/05/03/parsing-html-with-python.html">Unethical Blogger</a></p>
<p>This code parses any provided HTML content, and extracts a number of paragraphs specified, with all the content and tags inside them.</p>
<p>Example:
Template variable "content" contains:</p>
<pre><code><a href="#>some text</a>
<p><strong>Testing</strong>testing testing this is a tester's life</p>
<div>I wont see the world</div> …</code></pre>
Freely redistributablePrettify HTML body contents in HTTP response
2010-11-29T14:49:27.115538-06:00n1k0https://djangosnippets.org/snippets/2279/<p>This is an enhancement of snippet <a href="http://djangosnippets.org/snippets/172/">#172</a>. Here I use <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> — far more easier to install through pip in a virtualenv, and possibly a bit more maintained — to format and properly indent the rendered HTML from templates. </p>
<p>I also added a check to only tidy contents in …</p>
Freely redistributableHTML Email with Inline Attachments (images)
2010-10-01T17:45:07.517540-05:00hunterfordhttps://djangosnippets.org/snippets/2215/<p>This will allow you to attach HTML multipart emails (HTML/text) and use inline images.</p>
<p>In my example, I'm attaching an image that's stored as an 'attachment' to an 'event.' The file name of the attachment is called "inline.jpg" and I'm referencing it in my HTML message. I'm also attaching a …</p>
Freely redistributableurlize HTML
2010-06-18T18:51:01.277575-05:00maguspkhttps://djangosnippets.org/snippets/2072/<p>The default Django urlize filter does not work with html nicely so here I've used an HTML parser <a href="http://www.crummy.com/software/BeautifulSoup/">BeautifulSoup</a> to quickly search through each text node and run the django urlize filter on it. </p>
<p>Optimizations could be made to include a regex in the soup.findAll() method's text argument to only …</p>
Freely redistributableicon shortcut - pseudohtml tag with attribute merging and variables resolving
2010-06-02T04:32:03.132052-05:00wizhttps://djangosnippets.org/snippets/2048/<p>A shortcut for generating img-s with predefined classes and attributes that mimics a html tag, while resolving context variables inside {% %} without crutches like tag/stuff/endtag.</p>
<p>Used as <code>{% icon test class="spam" eggs="{{ object.pk }}" %}</code> yields <code><img src="http://host.tld/media/icons/test.png" alt="" class="icon16 spam" eggs="42"/></code>.</p>
<p>Not customizable here for simplicity.</p>
Freely redistributablestrip_tags like php one
2010-04-29T09:34:43.674873-05:00hommhttps://djangosnippets.org/snippets/2002/<p>Usage:</p>
<p><code>clean_html = strip_tags(html, {'a': ['href'], 'p': ['class']})</code></p>
<p>Based on <a href="http://www.djangosnippets.org/snippets/205/">another snippet</a>.</p>
Freely redistributableFieldsets for Views
2010-01-22T10:45:48.936419-06:00Nadhttps://djangosnippets.org/snippets/1883/<p>This Snippet allows a view to controle the printed forms on the templates, in a similar way to the fieldsets used by the django admin.</p>
<p>How to Use:</p>
<p>In the view in question, put:</p>
<pre><code>def some_view(request):
...
fieldsets = (
(u'Title 1',
{'hidden' : ('field_1', 'field_2',),
'fields' : ('field_3',)}),
(u'Title …</code></pre>
Freely redistributableAdmin Apps Names Translation
2010-01-22T09:14:33.127479-06:00Nadhttps://djangosnippets.org/snippets/1882/<p>This Snippet allows for your project's apps names to be displayed as you want in the Admin, including translations.</p>
<p>The lists of apps and languages are created from your settings.py file.</p>
<p><strong>How to use</strong></p>
<p>1st part:</p>
<ul>
<li>
<p>Create a application called 'apps_verbose' in you project with the models.py and admin.py showed …</p></li></ul>
Freely redistributableSanitize HTML filter with tag/attribute whitelist and XSS protection
2009-07-27T13:05:22.125896-05:00harrymhttps://djangosnippets.org/snippets/1655/<p>Reworked version of <a href="http://www.djangosnippets.org/snippets/205/">this snippet</a> that now accepts an argument so the user can specify which tags to allow, and which attributes should be allowed for each tag. Argument should be in form <code>tag2:attr1:attr2 tag2:attr1 tag3</code>, where tags are allowed HTML tags, and attrs are the allowed attributes for …</p>
Freely redistributable