Skip to main content

A Django middleware to check the html created by your application (during development)

Project description

django-check-html-middleware

This middleware for the Django Web Frameworks checks the HTML you create.

The middleware should only be used during development.

By default the middleware deactivates itself, if settings.DEBUG is False.

In Action

Imagine you have a typo in your HTML like this: <th>foo</td>, then you get a html page like this:

line 89, col 14: discarding unexpected </td>:
      <th>foo</td>

Anachronism?

Many people send JSON instead of HTML over the wire these days....

I use htmx and function-based-views if I can choose :-)

Install

pip install django-check-html-middleware

settings.py

Add check_html.CheckHTMLMiddleware at the start of your middleware.

If you use the Django-Debug-Toolbar, then put the check-html middleware below it.

MIDDLEWARE = [
    'check_html.CheckHTMLMiddleware',
    ....
]

CHECK_HTML_IGNORE_MESSAGES: A list of strings. Each string is an error messages which should get ignored.

Defaults to:

[
    'trimming empty',
    'proprietary attribute',
    'missing <!DOCTYPE> declaration',
    'inserting implicit <body>',
    '''inserting missing 'title' element''',
    'moved <style> tag to <head>',
    'inserting implicit <p>',
    ]

CHECK_HTML_IGNORE_STARTSWITH_PATH: A list of strings. If a URL path starts with this string, this response does not get checked.

Defaults to:

[
    '/admin/',
    ]

Wrapper for "utidylib"

This middleware is just a thin wrapper for utidylib.

Feedback is welcome!

What do you think could get improved?

Please tell me and open an issue at github.

Thank you!

Development installation

python3 -m venv check-html-env
cd check-html-env/
. bin/activate
pip install -U pip wheel
git clone git@github.com:guettli/django-check-html-middleware.git
mv django-check-html-middleware code
pip install -e code
cd code

pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-check-html-middleware-2021.5.3.tar.gz (3.6 kB view details)

Uploaded Source

File details

Details for the file django-check-html-middleware-2021.5.3.tar.gz.

File metadata

  • Download URL: django-check-html-middleware-2021.5.3.tar.gz
  • Upload date:
  • Size: 3.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.5

File hashes

Hashes for django-check-html-middleware-2021.5.3.tar.gz
Algorithm Hash digest
SHA256 fca7f8ed76c1035a54ed36c7825594a5b2066cae2353f96a53739995fef4e2ec
MD5 193957ba84f872ed7b2f5959fcf65b5a
BLAKE2b-256 30980ba9a4c1c923b16dc08e0df3d3e0133f0b2589748ec9e6b048df02fe37a9

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page