{ "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": "[![PyPI version](https://badge.fury.io/py/django-canonical-amp.svg)](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 \"\" \"\" %}` like in the following example:\n\n```html\n{% if youtube_id %}\n{% amp.require_component \"amp-youtube\" %}\n\n{% endif %}\n```\n\n If `youtube_id` evaluates to `False` in the above example the `amp-youtube` extension would not be injected to your page and it would stay AMP valid.\n\nThe version can be omitted. It will then default to 0.1.", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/matthiasrohmer/django-amp", "keywords": "", "license": "Apache License 2.0", "maintainer": "", "maintainer_email": "", "name": "django-canonical-amp", "package_url": "https://pypi.org/project/django-canonical-amp/", "platform": "", "project_url": "https://pypi.org/project/django-canonical-amp/", "project_urls": { "Homepage": "https://github.com/matthiasrohmer/django-amp" }, "release_url": "https://pypi.org/project/django-canonical-amp/0.1b1/", "requires_dist": null, "requires_python": "", "summary": "Template tags and middlewares to build canonical AMP pages with Django easily.", "version": "0.1b1" }, "last_serial": 5369078, "releases": { "0.1b0": [ { "comment_text": "", "digests": { "md5": "9bc7bf2a10674cc12349225df69e1895", "sha256": "3c52d66092030e5cad76f31dc5c91c8f201497b87778a31e8df9804ff135845b" }, "downloads": -1, "filename": "django-canonical-amp-0.1b0.tar.gz", "has_sig": false, "md5_digest": "9bc7bf2a10674cc12349225df69e1895", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4702823, "upload_time": "2019-06-04T21:37:24", "url": "https://files.pythonhosted.org/packages/58/f0/aaabe1d31afb523ef599d666055646515c8c70aca520295cee81a1083f3c/django-canonical-amp-0.1b0.tar.gz" } ], "0.1b1": [ { "comment_text": "", "digests": { "md5": "ee99cb455aa691fce254d5073234b3c5", "sha256": "947c546477b9915c889432db1b95d3f1f8f494d35fb1b075c7fd442de9f3aac2" }, "downloads": -1, "filename": "django-canonical-amp-0.1b1.tar.gz", "has_sig": false, "md5_digest": "ee99cb455aa691fce254d5073234b3c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4702861, "upload_time": "2019-06-06T21:23:34", "url": "https://files.pythonhosted.org/packages/ef/11/40338167c680f218cbc03b3dbc239152c2da9994e443c9035d8e4cb5f152/django-canonical-amp-0.1b1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "ee99cb455aa691fce254d5073234b3c5", "sha256": "947c546477b9915c889432db1b95d3f1f8f494d35fb1b075c7fd442de9f3aac2" }, "downloads": -1, "filename": "django-canonical-amp-0.1b1.tar.gz", "has_sig": false, "md5_digest": "ee99cb455aa691fce254d5073234b3c5", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 4702861, "upload_time": "2019-06-06T21:23:34", "url": "https://files.pythonhosted.org/packages/ef/11/40338167c680f218cbc03b3dbc239152c2da9994e443c9035d8e4cb5f152/django-canonical-amp-0.1b1.tar.gz" } ] }