Login

Snippets by newmaniese

Snippet List

Template range tag

This is a simple tag that I am sure has been written before, but it helps people with the problem, 'how do I iterate through a number in the tempaltes?'. Takes a number and iterates and returns a range (list) that can be iterated through in templates Syntax: {% num_range 5 as some_range %} {% for i in some_range %} {{ i }}: Something I want to repeat\n {% endfor %} Produces: 0: Something I want to repeat 1: Something I want to repeat 2: Something I want to repeat 3: Something I want to repeat 4: Something I want to repeat

  • template
  • context
  • range
Read More

Django Registration without username

A simple adaptation of RegistrationFormUniqueEmail from django-registration http://code.google.com/p/django-registration to allow users to register without using a username. This works great with the code from this comment: http://www.djangosnippets.org/snippets/74/#c195 to allow users to completely eliminate the need for a username.

  • registration
  • auth
Read More

Simple Exception Response for AJAX debugging

When debugging AJAX with Firebug, if a response is 500, it is a pain to have to view the entire source of the pretty exception page. This is a simple middleware that just returns the exception without any markup. You can add this anywhere in your python path and then put it in you settings file. It will only unprettify your exceptions when there is a XMLHttpRequest header. Tested in FF2 with the YUI XHR. Comments welcome. EDIT: I recently changed the request checking to use the is_ajax() method. This gives you access to these simple exceptions for get requests as well (even though you could just point your browser there).

  • middleware
  • ajax
  • exception-handling
Read More

newmaniese has posted 3 snippets.