Middleware for applying AMP Renderer to the output of a request in Django.
Project description
Django AMP Renderer
Middleware for applying AMP Renderer to the output of a request in Django.
Usage
Install via PyPI:
pip install django-amp-renderer
To apply the middleware, add django_amp_renderer.middleware.AMPRenderingMiddleware
to MIDDLEWARE
in your Django settings file:
MIDDLEWARE = [
'django_amp_renderer.middleware.AMPRenderingMiddleware',
…
]
The middleware expects the variables AMP_RUNTIME_VERSION
and AMP_RUNTIME_STYLES
to be set in your Django settings file. For AMP_RUNTIME_VERSION, provide the current AMP runtime version number as a string (to avoid losing leading zeroes), and for AMP_RUNTIME_STYLES, provide the full contents of https://cdn.ampproject.org/v0.css.
AMP_RUNTIME_VERSION = '012007242032002' AMP_RUNTIME_STYLES = """html{overflow-x:hidden!important}…"""
AMPRenderer has optional comment removal and attribute trimming. Those are disabled by default; To access them, use a subclass of the middleware and set the variables to True. They are passed along to the renderer.
class TransformingMiddleware(AMPRenderingMiddleware):
should_strip_comments = True
should_trim_attributes = True
Testing, etc.
Sort imports (Requires Python >= 3.5):
make normal
Lint (Requires Python >= 3.5):
make lint
Test:
make test
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for django-amp-renderer-1.0.0b1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 29ffe7d5c26fea882ba106c1cd20fb0260d1b79447f8942a044aaeb1501899da |
|
MD5 | 08b7c39ef4a5daf0a2c6f31304d918df |
|
BLAKE2b-256 | a4147fa01cec172422a756937f2d42ee084ac8b8562df7c07cb6cdf99fd764c2 |
Hashes for django_amp_renderer-1.0.0b1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 37ded052f1661d7ae4e29e94476ec8e47fb26f7e457358c06bf5fe45a9b84d85 |
|
MD5 | 1e2333cf09e122d9d80d47f4280c50b2 |
|
BLAKE2b-256 | 8ef1c4477e3d977c9e8310f3cccd49f7c58968a45b9ff34ca31e6d1790322281 |