If you chose to set it up as a middleware and enable it accordingly it willrun for every rendered template in the tests too. Not just when you run theserver.

Settings--------

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

```pythonHTMLVALIDATOR_ENABLED = True```

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 validationerror switch this on in your settings:

```pythonHTMLVALIDATOR_FAILFAST = True```

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

Equally, if you're running it as a middleware and have this setting on itwill raise the exception in the request.

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

```pythonHTMLVALIDATOR_DUMPDIR = '~/validationerrors/' # default it /tmp```Whatever you set, the directory doesn't need to exist but its parent does.

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

```pythonHTMLVALIDATOR_OUTPUT = 'stdout' # default is 'file'```

Setting the vnu.jar path------------------------

By default, all validation is done by sending your HTML with HTTP POST to[html5.validator.nu](https://html5.validator.nu/)

Not only does this put a lot of stress on their server. Especially if you havea lot of tests. It's also slow because it depends on network latency. A muchbetter way is to download the `vnu.jar` file from their[latest release](https://github.com/validator/validator/releases) on[GitHub page](https://github.com/validator/)

You set it up simply like this:

```pythonHTMLVALIDATOR_VNU_JAR = '~/downloads/vnu.jar'```

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

Be aware that calling this `vnu.jar` file is quite slow. Over 2 seconds isnot unusual. A faster alternative is to use the `vnu.jar` to run a local webinstance of the validator, and pointing validation to use that by *NOT* setting`HTMLVALIDATOR_VNU_JAR` and doing this instead:

```pythonHTMLVALIDATOR_VNU_URL = 'http://localhost:8888/'```

The local web instance of the validator can be started typically by:

```java -cp vnu.jar nu.validator.servlet.Main 8888```

Validating during running the server------------------------------------

A way to do HTML validation is to do it during running theserver. E.g. with `./manage.py runserver`.

To do that you need to enable the middleware. In your settings module,append `htmlvalidator.middleware.HTMLValidator`to `MIDDLEWARE_CLASSES` for example like this:

You can also add it directly and unconditionally to `MIDDLEWARE_CLASSES`and it won't do anything (except be loaded) unless enabled, seethe note above about `HTMLVALIDATOR_ENABLED` for more info.

Also, if you enable `HTMLVALIDATOR_FAILFAST`, when running the`htmlvalidator` middleware it will raise an exception as soon as itsees 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 toreplace it with the `htmlvalidator.client.ValidatingClient`class. For example: