skip to navigation
skip to content

Not Logged In

django-output-validator 1.5

App to catch HTML errors (or other errors) in outgoing Django pages.

This project is no longer under active development, and may not work with modern versions of Django. The primary reasons for this are 1) that I have been unable to find any robust command line validators for HTML5, and 2) I rarely worry about HTML5 validation due to my frustrations with the spec and its authors which go out of their way to make life difficult for tool authors e.g. bug 12561

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.

  • Add "output_validator" to your INSTALLED_APPS setting.

  • If you have removed "django.template.loaders.app_directories.Loader" from your TEMPLATE_LOADERS, you need to add the 'templates' folder to your TEMPLATE_DIRS setting.

  • 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 = [
          '/admin/',
      ]
      

Usage

When browsing any of your pages in development, all HTML will be validated. If it fails, it will be logged. You can see all failures at 'http://localhost:8000/validator/' (assuming local development and the URL conf suggested above). Use the app to delete old failures once they have been fixed.

Changelog

Version 1.5 - 2010-12-01

  • Re-branded as django-output-validator and packaged properly.

    If you used the previous version, you should drop the old 'validator_validationfailure' table (assuming it doesn't have any data you need, of course). Then go through the installation instructions in the README and update the name/values of the relevant settings.

  • Fixed stashing of request objects (now uses repr). This is BACKWARDS INCOMPATIBLE with existing data (but we are using a new table anyway).

Version 1.4 - 2008-04-28

  • Changed maxlength to max_length, as per change in Django.
  • Corrections to instructions (thanks to Gary Wilson)
  • Fixed deprecation warnings (thanks to Gary Wilson)

Version 1.3 - 2007-11-05

  • Updated for unicodisation of Django.

    This is a BACKWARDS INCOMPATIBLE change.

    The problem was caused by the fact that you used to able to store arbitrary binary data in a TextField, which is no longer possible. As a result, I am using base64 encoding for any pickled objects. I haven't written an upgrade script for the database (since I personally keep the list of failed pages to zero). If you are upgrading from a previous version, any of your existing ValidationFailure objects will be corrupted (the 'request' and 'response' data will be lost). Either deal with the errors before upgrading, or write a conversion script of some kind :-)

Version 1.2 - 2007-04-18

  • Fixed bug that occurred when settings.VALIDATOR_APP_IGNORE_PATHS wasn't set
  • Added logic to stop duplicate failures being logged

Version 1.1 - 2005-12-14

  • Added optional VALIDATOR_APP_IGNORE_PATHS setting.
  • Added support for mod_python handler - thanks to 'nesh'.
  • Added a setup.py script.

Version 1.0 - 2005-11-19

  • Initial release
 
File Type Py Version Uploaded on Size
django-output-validator-1.5.tar.gz (md5) Source 2010-12-01 9KB
  • Downloads (All Versions):
  • 4 downloads in the last day
  • 62 downloads in the last week
  • 270 downloads in the last month