This middleware looks for a _filter query string in a request. If it is present and the response has a content-type of text/html only the element with the given id will be returned. If the id is not found in the response an empty div element will be returned.

To illustrate this behaviour lets assume that a backend server generates this response:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
<html xmlns="">
    <title>Test document</title>
    <h1 id="header">Test document</h1>
    <div id="body">
      <p>Welcome to our little test</p>

If a browsers requests this document using a request for the document will be returned untouched.

Lets suppose that AJAX capability is being added to your site and you need to inject the header from this document. Fetching the whole document from the server and extracting the header element fmor the document can be expensive. This is very noticable in older versions of IE which are very slow in building a DOM for the requested data and extracting the right bits form it. Instead of fetching the full document and extracting the right you can ask repoze.slicer to do the filtering by making a request for The returned data will then look like this:

<h1 id="header">Test document</h1>


  • Only responses with a status code of 200 are filtered.
  • Only valid XML documents can be processed. Responses which can not be parsed using the lxml XML parser will be returned unmodified.

Adding repoze.slicer To Your WSGI Pipeline

Via PasteDeploy .INI configuration:

 pipeline =

Via Python:

from otherplace import mywsgiapp

from repoze.slicer import SlicerApp
new_wsgiapp = SlicerApp(mywsgiapp)