The Middlewares

class fusionbox.middleware.GenericTemplateFinderMiddleware[source]

Response middleware that uses generic_template_finder_view() to attempt to autolocate a template for otherwise 404 responses.

process_response(request, response)[source]

Ensures that 404 raised from view functions are not caught by GenericTemplateFinderMiddleware.

process_view(request, view_func, view_args, view_kwargs)[source]

Informs process_response() that there was a view for this url and that it threw a real 404.

class fusionbox.middleware.Redirect(source, target, status_code, filename, line_number)[source]

Encapulates all of the information about a redirect.

class fusionbox.middleware.RedirectFallbackMiddleware(*args, **kwargs)[source]

This middleware handles 3xx redirects and 410s.

Only 404 responses will be redirected, so if something else is returning a non 404 error, this middleware will not produce a redirect

Redirects should be formatted in CSV files located in either <project_path>/redirects/ or an absolute path declared in settings.REDIRECTS_DIRECTORY.

CSV files should not contain any headers, and be in the format source_url, target_url, status_code where status_code is optional and defaults to 301. To issue a 410, leave off target url and status code.

fusionbox.middleware.generic_template_finder_view(request, *args, **kwargs)[source]

Find a template based on the request url and render it.

  • / -> index.html
  • /foo/ -> foo.html OR foo/index.html
fusionbox.middleware.preprocess_redirects(lines, raise_errors=True)[source]

Takes a list of dictionaries read from the csv redirect files, creates Redirect objects from them, and validates the redirects, returning a dictionary of Redirect objects.