A couple of years ago I released a project called django-html-validator (GitHub link) and it's basically a Django library that takes the HTML generated inside Django and sends it in for HTML validation.
The first option is to send the HTML payload, over HTTPS, to https://validator.nu/. Not only is this slow but it also means sending potentially revealing HTML. Ideally you don't have any passwords in your HTML and if you're doing HTML validation you're probably testing against some test data. But... it sucked.
The other alternative was to download a
vnu.jar file from the github.com/validator/validator project and executing it in a subprocess with
java -jar vnu.jar /tmp/file.html. Problem with this is that it's really slow because java programs take such a long time to boot up.
But then, at the beginning of the year some contributors breathed fresh life into the project. Python 3 support and best of all; the ability to start the
vnu.jar as a local server on
http://localhost:8888 and HTTP post HTML over to that. Now you don't have to pay the high cost of booting up a java program and you don't have to rely on a remote HTTP call.
Now it becomes possible to have HTML validation checked on every rendered HTML response in the Django unit tests.
To try it, check out the new instructions on "Setting the vnu.jar path".
The contributor who's made this possible is Ville "scop" Skyttä, as well as others. Thanks!!
You can write a 5 lines HTML validator middleware used only in unit test with the html5lib python library.