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}…
""".strip()
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.6):
make normal
Lint (Requires Python >= 3.6):
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.0b3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 71ec6b46ae7464f6b8f07363d6ddd0eae69fd5fb95eb9abf405e732a15f1593c |
|
MD5 | 81513d3d5890e2c61f1b902c915d3d22 |
|
BLAKE2b-256 | b865cd2411292702040d9ef6576f096a84f8165e862986e6af769f5ebdb6007f |
Hashes for django_amp_renderer-1.0.0b3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d0788134f3b410101e8e7ba12f1ed098beb032268f45b4fc41cad52f2ce0e0d0 |
|
MD5 | 24ca7fc9eb0452b284d7af950f608ed7 |
|
BLAKE2b-256 | 4093d12dd953a98a7fa78f2fb104750433088e8680f5a4fb9aee4bcf9ad00449 |