fix pep8, pyflakes, unicodes

There should only be flake8 errors in contrib and migrations now.
Make test_entities happy

by avoiding non-html entities in html files, even if used in python
code. This should be fixed in the test_entities test, but this is a bit
hard, and it's a good idea to make use of base_url parameters.