# django-output-validator2 /

Filename Size Date modified Message
output_validator
126 B
1.9 KB
82 B
2.7 KB
1.2 KB

# Django output validator

This app validates all the HTML (or potentially other data) that is generated by your Django project. This is meant to be used only in development.

## Installation

• Run setup.py to install the package into your python path, or use easy_install django-output-validator (or pip).

• Insert the middleware "output_validator.middleware.ValidatorMiddleware" near the beginning of the middleware list (which means it will get the the response object after everything else). It must be after every middleware that does post-processing, but mustn't be after GZip, since it can't handle gzipped HTML. ( I just disable the GZip middleware for development)

• Alter your URL conf to include the URLs for the validator. You need this line inserted somewhere:

(r'^validator/', include('output_validator.urls'))

• Add a setting to tell the app where to find the 'validate' executable used for validation. This is a dictionary of mimetypes and corresponding validators, allowing this app to be extended to any other generated content:

OUTPUT_VALIDATOR_VALIDATORS = {
'text/html': '/usr/bin/validate',
'application/xml+xhtml': '/usr/bin/validate',
}


I usually use a small wrapper for this executable that pops up a message when it fails - the following works for GNOME (if you have the notify-send program installed):

#!/bin/sh
validate "\$1" || {
notify-send "Validation failed";
}

• Finally, run the django admin script to set up the database tables:

./manage.py --settings="yourproject.settings" syncdb


OR, if you are using South:

./manage.py --settings="yourproject.settings" migrate output_validator

• Optionally, set the following settings:

• OUTPUT_VALIDATOR_IGNORE_PATHS - this is a list of path prefixes that will be ignored. For example, if you have the admin at /admin/ you can ignore any errors in the admin with this:

OUTPUT_VALIDATOR_IGNORE_PATHS = [