This middleware will use the W3 Validator Service to check if your page is valid HTML. It will only check each URI once so that it doesn’t slow down your site by validating every page load. It does this by placing the result of each URI into a memory cache(using Beaker). You can then call cache_is_valid_xhtml() in your template to determine if the current page is valid.
Note: The first time your page loads it will not display if the page is valid or not(It is validated AFTER the first response).
Source Download(gzipped): http://www.tech9computers.com/w3validator.tar.gz
At the top of your middleware.py import the following
Then right below CUSTOM MIDDLEWARE HERE
At the top you need to import cache_is_valid_xhtml()
I then created the following method that I call from my templates to return a string saying if the page is valid or not.
If you have a base template, you might want to the footer of every page to display if it is valid (X)HTML or not.
That’s all you need to do to add validation support to your site. You can check the middleware out in action on my site at http://blackberrytracker.com. Scroll to the bottom of the page to see where I have the validation result.