{ "info": { "author": "Matthias Rohmer", "author_email": "rohmer.matthias@anyvent.org", "bugtrack_url": null, "classifiers": [ "Environment :: Web Environment", "Framework :: Django", "Framework :: Django :: 2.1", "Intended Audience :: Developers", "License :: OSI Approved :: Apache Software License", "Operating System :: OS Independent", "Programming Language :: Python", "Programming Language :: Python :: 3.5", "Programming Language :: Python :: 3.6", "Topic :: Internet :: WWW/HTTP", "Topic :: Internet :: WWW/HTTP :: Dynamic Content" ], "description": "[](https://badge.fury.io/py/django-canonical-amp)\n\n# django-canonical-amp\n\nA small set of tools meant to make building canonical [AMP](https://amp.dev) pages with [Django](https://www.djangoproject.com/) a little easier.\n\n## Installation\n\nTo enable the functionality of this package you need to add it to various keys of your project settings (settings.py per default) just as with other Django apps.\n\n#### INSTALLED_APPS\ndjango-canonical-amp needs to be added to your installed apps.\n\n```python\nINSTALLED_APPS = [\n # ...\n 'amp',\n]\n```\n\n#### TEMPLATES\nAdditionally you need to update your template settings to use the django-canonical-amp backend which is just a wrapper around Django's default backend.\n\n\n```python\nTEMPLATES = [\n {\n 'BACKEND': 'amp.template.backends.amp.AmpTemplates',\n # ...\n },\n]\n```\n\n#### MIDDLEWARE\nThis step is optional but if you want to serve [server-side-rendered AMP](https://github.com/ampproject/amphtml/blob/master/spec/amp-cache-modifications.md) straight from your Django app you can add the transformer middleware to your stack.\n\n**Important:** this is experimental. The transformations happen by using a shared library built from the Go implementation of the [amppackager](https://github.com/ampproject/amppackager/tree/releases/transformer). This package ships with compiled versions for *linux/amd64* and *darwin/amd64* operating systems.\n\nIf you want to use this middleware you also need to make sure your production system is able to perform requests to https://cdn.ampproject.org/rtv/metadata for the transformer to be able to fetch the current runtime version.\n\n```python\nMIDDLEWARE = [\n # ...\n 'amp.middleware.AmpOptimizerMiddleware',\n]\n```\n\nThis middleware needs to execute before Django's `django.middleware.gzip.GZipMiddleware` for the transformer to be able to alter the response.\n\nIf you make use of this middleware you can additionally set `AMP_REWRITE_URLS` in your settings to `False`. By doing so you instruct the transformer to leave your URLs alone and don't rewrite them to a AMP cache URL - this comes with pros and cons: delivery times might be better from the cache though there's no guarantee your content (and assets) are already available from the cache. This settings defaults to `not DEBUG` to don't rewrite URLs for all non-production environments.\n\nAMP components relying on API endpoints served by your application need them to be served according to [AMP's CORS specification](https://amp.dev/documentation/guides-and-tutorials/learn/amp-caches-and-cors/amp-cors-requests). django-canonical-amp ships with another middleware that adds the required headers. For it to work make sure your server is able to access https://cdn.ampproject.org/caches.json. Then add the middleware to your stack:\n\n```python\nMIDDLEWARE = [\n # ...\n 'amp.middleware.AmpCorsMiddleware',\n]\n```\n\n## Usage\nThe basic functionality of the package are two template tags that are available after installation. They make it able to dynamically define used [AMP components](https://amp.dev/documentation/components/). For them to and up in the `
` of your HTML make sure you add the `{% amp.components %}` tag like so:\n\n```html\n{% load amp %}\n\n\n\n \n \n \n \n\n \n \n\n {% amp.components %}\n \n\n \n```\n\nSomewhere else in your templates you can then define dependencies by calling `{% amp.require_component \"