Django AMP Renderer
Middleware for applying AMP Renderer to the output of a request in Django. Tested in Python 3.8 and above, but works on Python 3.6+.
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). 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):
strip_comments = True
trim_attributes = True
You can apply the middleware to all requests, even non-AMP pages. The transformations will only be applied if the document contains the v0.js script (https://cdn.ampproject.org/v0.js).
If the transformation is applied, the Boilerplate-Status header of the response will either be set to "Removed" or "Ignored", based on whether the boilerplate was able to be removed by the renderer.
Testing, etc.
Install development requirements (Requires Python >= 3.8):
make install
Sort imports:
make format
Lint:
make lint
Test:
make test
Metadata
Release files for django-amp-renderer 2.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django_amp_renderer-2.2.0.tar.gz | 9.1 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| django_amp_renderer-2.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 19.0 kB
Release files / django_amp_renderer-2.2.0.tar.gz
| Download URL | django_amp_renderer-2.2.0.tar.gz |
|---|---|
| Size | 9.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
87c1316cec576abfc85ebde960ac39ce6b9e85e0189a4fa0d7adb05b31fe7d7b
|
|
BLAKE2b-256 checksum How to use checksums |
c16585b9962a21cd492bf757e72ee89c5fad51f0460f6120858cd74fb94d29be
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Release files / django_amp_renderer-2.2.0-py3-none-any.whl
| Download URL | django_amp_renderer-2.2.0-py3-none-any.whl |
|---|---|
| Size | 9.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
041ece5818f74a1a10d0195c93026915c461eb0d965cd6e6230ca5df15b91e46
|
|
BLAKE2b-256 checksum How to use checksums |
3ae2bfc283d69ffe7a8a02ed9c88d0693b1c9efc601465719afecdcbe726a37c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.1.0 CPython/3.13.7
|
Security for django-amp-renderer 2.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.