Accelerated mobile pages in django?

Are Django developers ready to create AMP-HTML pages?

(For reference: Google AMP project )

If I understand correctly how AMP-HTML works, you create 2 separate files for each page. Normal HTML result, plus a new AMP-HTML file. The AMP-HTML file is a smaller version of a regular HTML page and is used by Google to return an accelerated mobile page (hence the name Accelerated Mobile Pages). Each of these files refers to each other in a tag in the head that tells Google to use the AMP file for mobile results.

As part of Django, I am wondering how to create 2 separate files based on the same set of content.

How can one context be used that can be passed along with two HTML results? One result is a plain HTML page, the other is an AMP-HTML page.

In Django, a URL must be created for each page returned. How can I automatically create a second URL for every existing URL? Also, how can one context be invoked for each of these URLs?

Perhaps this is possible in the view? For example, return the extension .html, which is an AMP page, and then also create a template for the URL?

I have no answers yet how to solve this. Look for feedback and suggestions. This seems to be the first ever question posted on stackoverflow in Django and AMP-HTML. This will probably not be the last.

+7
django amp-html accelerated-mobile-page
source share
3 answers

I am a Django AMP developer, but definitely not an expert, we use the following URL pattern

url(r'^api/news/', include('news.api_urls'), {"type", "regular"}), # regular url(r'^api/amp/news/', include('news.api_urls'), {"type": "amp"}), # AMP 

and in the view generating a different context that needs to be passed to the templates, the canons in the templates point to each other and seem to work

+4
source share

In the view, you can set the template variable in several ways, for example, in the GET request parameter:

 if request.GET.get('amp', 0) == 1: template_name = "amp.html" else: template_name = "regular.html" 

You can pass template_name as a variable to a context that can then be used to render the page:

 {% extends template_name %} 

This will allow you to display two completely different layouts using the same view code / URL / context.

+3
source share

I am creating an application https://github.com/shtalinberg/django-amp-tools for this

{% load amp_tags %} in the template

{% amp_canonical_link request %} in meta

and create the amp folder in the templates

This is the first issue. more documentation and futures will be added

+1
source share

All Articles