Login

All snippets written in HTML/template

Snippet List

Captcha Middleware (Template)

A middleware we are using to stop "spam" on Curse. It makes the user fill in a captcha box whenever they submit a form unless a cookie is set (which expires by default after 6 hours) See also [the python script](http://www.djangosnippets.org/snippets/127/)

  • captcha
  • anti-spam
Read More

Template Query Debug

I often find something like this lurking at the end of my base templates - it'll show you which queries were run while generating the current page, but they'll start out hidden so as not to be a pain. Of course, before this works, you'll need to satisfy all the criteria for getting debug information in your template context: 1. Have `'django.core.context_processors.debug'` in your `TEMPLATE_CONTEXT_PROCESSORS` setting (it was there in the default settings, last time I checked). 2. Have your current IP in your `INTERNAL_IPS` setting. 3. Use [RequestContext](http://www.djangoproject.com/documentation/templates_python/#subclassing-context-requestcontext) when rendering the current template (if you're using a generic view, you're already using `RequestContext`).

  • template
  • debug
  • queries
Read More

Using the {% widthratio %} template tag with CSS to create a bar graph

The {% widthratio %} template tag is under appreciated! Here, it's combined with CSS to create a bar graphic for the results of an election (this example comes from [this page](http://flickr.com/photos/postneo/405239750/in/photostream/), but has been modified slightly for simplicity's sake). The widthratio tag can be used to create all sorts of graphs and charts, as well as things like tag clouds. Here, we pass it the number of votes for a candidate, the total number of votes in the election, and the integer 190, which is the width, in pixels, of a "full" bar on the bar graph. In other words, 100% = 190 pixels. It works great!

  • template
  • templatetag
  • widthratio
  • graph
  • infographic
Read More

78 snippets posted so far.