skip to navigation
skip to content

django-html-validator 0.3

Yo! Check your HTML!

Latest Version: 0.4.5


A tool to do validation of your HTML generated from your Django app.

License: [MPL 2](


If you don't download a local `vnu.har` file, it will use
`` and send your HTML there over HTTP.
Not over HTTPS.

If you use `htmlvalidator` to validate tests it's unlikely your HTML contains
anything sensitive or personally identifyable but if you use the middleware
option there's a potential risk.


Independent of how you use `htmlvalidator` you need to switch it on.
It's not on by default. The setting to do that is:


What this does, is that it prints all validation errors to `stdout`.
But it doesn't stop the execution from running. Even if there are errors.

To make it so that the execution stops as soon as there is any validation
error switch this on in your settings:


Now, if there's any validation error going through the client you'll
get a `htmlvalidator.exceptions.ValidationError` exception raised.

When validation errors and warnings are encountered, `htmlvalidator` will
dump the HTML to a file and the errors in a file with the same name except
with the extension `.txt` instead. It will dump this into, by default, the
systems tmp directory and in sub-directory called `htmlvalidator`.
E.g. `/tmp/htmlvalidator/`. If you want to override that change:

HTMLVALIDATOR_DUMPDIR = '~/validationerrors/'
Whatever you set, the directory doesn't need to exist but its parent does.

By default when `htmlvalidator` encounters validation errors it stores
the relevant HTML file in the `HTMLVALIDATOR_DUMPDIR` together with a file
with the extension `.txt` in the same directory. Alternatively you can just let
it dump the validation errors and warnings straight onto stdout with:

HTMLVALIDATOR_OUTPUT = 'stdout' # default is 'file'

Setting the vnu.jar path

By default, all validation is done by sending your HTML with HTTP POST to

Not only does this put a lot of stress on their server. Especially if you have
a lot of tests. It's also slow because it depends on network latency. A much
better way is to download the `vnu.jar` file from their
[latest release]( on
[GitHub page](

You set it up simply like this:

HTMLVALIDATOR_VNU_JAR = '~/downloads/vnu.jar'

This also **requires java to be installed** because that's how `.jar` files are
executed on the command line.

Be aware that calling this `vnu.jar` file is quite slow. Over 2 seconds is
not unusual.

Validating during running the server

A way to do HTML validation is to do it during running the
server. E.g. with `./ runserver`.

To do that you need to enable the middleware. In your settings module,
`htmlvalidator.middleware.HTMLValidator` so it looks something like

'htmlvalidator.middleware.HTMLValidator', # <-- note!

Note! See the note above about `HTMLVALIDATOR_ENABLED` to actually
make it do something.
Also, if you enable `HTMLVALIDATOR_FAILFAST`, when running the
`htmlvalidator` middleware it will raise an exception as soon as it
sees some invalid HTML.

Validating HTML in tests

Suppose you have a class that does tests. By default it already has a
`self.client` which you use to make requests. All you need to do is to
replace it with the `htmlvalidator.client.ValidatingClient`
class. For example:


from django.test import TestCase
from htmlvalidator.client import ValidatingClient

class MyAppTests(TestCase):

def setUp(self):
super(MyAppTests, self).setUp()
self.client = ValidatingClient()

def test_homepage(self):
response = self.client.get('/')
self.assertEqual(response.status_code, 200)
File Type Py Version Uploaded on Size
django-html-validator-0.3.tar.gz (md5) Source 2014-09-04 5KB
django_html_validator-0.3-py2-none-any.whl (md5) Python Wheel 2.7 2014-09-04 9KB
  • Downloads (All Versions):
  • 0 downloads in the last day
  • 0 downloads in the last week
  • 773 downloads in the last month