# django-output-validator

 Luke Plant 61e8785 2010-12-01 Luke Plant a389f3c 2010-12-01 Luke Plant 61e8785 2010-12-01   1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 ======================= 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. * 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.