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.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.0b2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 27cc4b3e0d7a62175e5396a3d624d38fbe21e85605f5c054f5d61f1008d2abfc |
|
MD5 | 60462779cf5c49a172c5e0feda4204c6 |
|
BLAKE2b-256 | 43584e0cd487923a344e9df867834da546d6bd483e673ea05461edfd6312ff6f |
Hashes for django_amp_renderer-1.0.0b2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9894a5e778c3c64a48e96b2008f2d3aebcd9b6cd8c1357273fd45a44b999b5f7 |
|
MD5 | 026ace7653591895ba76bd56097a1c79 |
|
BLAKE2b-256 | 674a318bf586191f49f37e19f29c597f11e5d7f81e60e8a178a062c99631c49c |