Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Python HTML JavaScript

This branch is 35 commits ahead, 250 commits behind master

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.


Useful tools for Django development.

GenericTemplateFinderMiddleware This middleware will automatically find a

template based on the request url and render it. Useful during early design stages to allow quick static pages to use the template system.

Add fusionbox.middleware.GenericTemplateFinderMiddleware to your MIDDLEWARE_CLASSES to activate.

Usage examples

  • / renders index.html
  • /foo/ renders /foo.html OR /foo/index.html OR /foo
  • This works for any directory depth

RedirectFallbackMiddleware Middleware for handling 3xx redirects and 410

pages. Scrapes /redirects/ in your project, or a path defined in settings.REDIRECTS_DIRECTORY for any CSV files. CSV files should be in the format of old_url, new_url, status_code. If status_code is omitted, a 301 will be issued. If both new_url and status_code are omitted, a 410 will be issued. Both url fields can be either relative or fully qualified urls. Redirects will only be issued for pages which would normally result in a 404.

Errors are raised when any url produces a redirect chain. Since fully qualified urls are accepted, warnings are raised in the event that a redirect could produce a circular redirect dependent on the site's domain.

This middleware should be placed before django's built in 'CommonMiddleware'.

Add fusionbox.middleware.RedirectFallbackMiddleware to your MIDDLEWARE_CLASSES to activate. Run ./ validate_redirects to check redirects for problem and view any warnings raised.

Example Valid CSV, /bar/, /asdf/, 302

Example CSV with circular redirects or error redirects, /bar/, /baz/, /bar/

Example CSV with redirects which raise warnings.



Behaviors are a DRY way of re-using common fields and methods on models. Behaviors function seamlessly through python inheritance and are fully configurable. Behaviors also support multi-inheritance so adding multiple behaviors to a single model is as easy as inheriting from each behavior you wish to add.

Standard Usage from fusionbox.behaviors import TimeStampable

class Foo(TimeStampable): pass

This will add the fields created_at and updated_at to your Foo model.

Just as their names suggest, the model will have the following fields.

  • created_at => DateTimeField(auto_now_add=True)
  • updated_at => DateTimeField(auto_now=True)

Custom Configuration Usage from fusionbox.behaviors import TimeStampable

class Foo(TimeStampable): class TimeStampable: created_at = "creation_date"
updated_at = "date_updated"

This will add the same fields as in the standard usage, but the fields will instead be named creation_date and date_updated respectively


Put {% load fusionbox_tags %} in your template to use these.

{% higlight_here %}

This template tag will parse all anchor tags between higlight_here and endhighlight and add a class to the ones that are considered 'parents' of the current page's url. It takes an optional class name as an argument, defaulting to here.

Usage examples

    {% highlight_here %} <a href="/" class="home">/</a> <a
    href="/blog/">blog</a> {% endhighlight %}

    {% highlight_here big red %} <a href="/">/</a> <a
    href="/blog/">blog</a> {% endhighlight %}


require_PUT, require_DELETE - just like the built-in require_POST and require_GET decorators.

require_AJAX - uses django's request.is_ajax() method, returns HttpResponseBadRequest if the request is not an AJAX request.

@require_AJAX def my_view(request): pass

require_JSON - makes sure that the Content-Type header is application/json, and parses the JSON if it is. Assigns the result to request.payload. If an error occurs, an HttpResponseBadRequest is returned.

@require_JSON def my_view(request): print request.payload



Mixin form class which provides a searching interface on a model


Mixin form class which provides singular and progressive sorting on a model along with headers for use in template rendering.


Mixin form class which provides a filtering interface on a model


Forms inheriting from these form mixin classes should be instantiated with request.GET along with an optional initial queryset.

FooSearchForm(request.GET, queryset=User.objects.filter(is_active=True)

These form mixins provide a get_queryset method which handles all of the filtering, searching, and/or sorting logic.

Something went wrong with that request. Please try again.