django-amp-tools Documentation Release latest

Similar documents
Django AdminLTE 2 Documentation

django simple pagination Documentation

django-baton Documentation

Django MFA Documentation

django-baton Documentation

django-responsive2 Documentation

Django-CSP Documentation

Markup Language. Made up of elements Elements create a document tree

AGENDA. EMBEDDING FONTS [ Font Files & CSS font-family ] :: Online Font Converter :: ADD font-family css code to style.css

Introduction to WEB PROGRAMMING

django-ad-code Documentation

django-sekizai Documentation

django-session-security Documentation

MIT AITI Python Software Development Lab DJ1:

TailorDev Contact Documentation

django-cas Documentation

Quick.JS Documentation

HTML Summary. All of the following are containers. Structure. Italics Bold. Line Break. Horizontal Rule. Non-break (hard) space.

AGENDA. :: Add Meta Tag for Viewport (inside of head element): :: Add Script that renders HTML5 elements for older versions of Internet Explorer

Django Wordpress API Documentation

Stamp Builder. Documentation. v1.0.0

CSCI 1320 Creating Modern Web Applications. Content Management Systems

cmsplugin-blog Release post 0 Øyvind Saltvik

django-cms-search Documentation

alphafilter Documentation

Understanding this structure is pretty straightforward, but nonetheless crucial to working with HTML, CSS, and JavaScript.

micawber Documentation

django-auditlog Documentation

Django EL(Endless) Pagination Documentation

Front-End UI: Bootstrap

Hyper Text Markup Language

Design Document V2 ThingLink Startup

Introduction to HTML5

CID Documentation. Release Francis Reyes

As we design and build out our HTML pages, there are some basics that we may follow for each page, site, and application.

Multimedia Systems and Technologies Lab class 6 HTML 5 + CSS 3

Django PAM Documentation

wagtailtrans Documentation

django-osm-field Release 0.3.1

Chapter 7 BMIS335 Web Design & Development

BA. (Hons) Graphics Design

Hyper Text Markup Language

WEB DEVELOPMENT & DESIGN FOUNDATIONS WITH HTML5

django-idioticon Documentation

1/6/ :28 AM Approved New Course (First Version) CS 50A Course Outline as of Fall 2014

Summary. 1. Page 2. Methods 3. Helloworld 4. Translation 5. Layout a. Object b. Table 6. Template 7. Links. Helloworld. Translation Layout.

The starter app has a menu + 2 Views : Dashboard. About

django-avatar Documentation

Web Development and HTML. Shan-Hung Wu CS, NTHU

Lab 1: Introducing HTML5 and CSS3

django-messages Documentation

django-flickr Documentation

django-avatar Documentation

Session 5. Web Page Generation. Reading & Reference

Django Part II SPARCS 11 undead. Greatly Inspired by SPARCS 10 hodduc

django-intercom Documentation

AGENDA :: MULTIMEDIA TOOLS :: CLASS NOTES

Python Schema Generator Documentation

Style-Guidelines. Release 0.1

Django urls Django Girls Tutorial

HTML & CSS November 19, 2014

django-dajax Documentation

16. HTML5, HTML Graphics, & HTML Media 웹프로그래밍 2016 년 1 학기 충남대학교컴퓨터공학과

SEO Authority Score: 40.0%

AGENDA :: MULTIMEDIA TOOLS :: CLASS NOTES. INSTALLING FONTS :: Download, Install, & Embed Your Fonts. LECTURE :: Responsive Web Design [RWD]

For instructions to change the logo, please refer to: ore

Accessibility of EPiServer s Sample Templates

Bootstrap Carousel. jquery Image Sliders

Static Webpage Development

Programmazione Web a.a. 2017/2018 HTML5

Intro, Version Control, HTML5. CS147L Lecture 1 Mike Krieger

django-xross Documentation

colab Documentation Release 2.0dev Sergio Oliveira

Certified HTML5 Developer VS-1029

Instant Speed. with Google AMP and Facebook Instant Articles. Baris Wanschers

HTML5 and CSS3: New Markup & Styles for the Emerging Web. Jason Clark Head of Digital Access & Web Services Montana State University Library

nacelle Documentation

Building a Django Twilio Programmable Chat Application

Client Side Injection on Web Applications

Web Programming and Design. MPT Senior Cycle Tutor: Tamara Week 1

11. HTML5 and Future Web Application

django-image-cropping Documentation

Index. alt, 38, 57 class, 86, 88, 101, 107 href, 24, 51, 57 id, 86 88, 98 overview, 37. src, 37, 57. backend, WordPress, 146, 148

Django Leaflet Documentation

Skill Area 323: Design and Develop Website. Multimedia and Web Design (MWD)

Responsive Web Design and Bootstrap MIS Konstantin Bauman. Department of MIS Fox School of Business Temple University

Review of HTML. Chapter Pearson. Fundamentals of Web Development. Randy Connolly and Ricardo Hoar

django-private-chat Documentation

Django Image Tools Documentation

HTML5 and Mobile: New Markup & Styles for the Mobile Web. Jason Clark Head of Digital Access & Web Services Montana State University Libraries

DATABASE SYSTEMS. Introduction to web programming. Database Systems Course, 2016

The Django Web Framework Part II. Hamid Zarrabi-Zadeh Web Programming Fall 2013

CSI 3140 WWW Structures, Techniques and Standards. Markup Languages: XHTML 1.0

Downloads: Google Chrome Browser (Free) - Adobe Brackets (Free) -

DJOAuth2 Documentation

Purpose of this doc. Most minimal. Start building your own portfolio page!

Programming of web-based systems Introduction to HTML5

kiss.py Documentation

django-stored-messages Documentation

Building a Python Flask Website A beginner-friendly guide

Transcription:

django-amp-tools Documentation Release latest February 07, 2017

Contents 1 Installation 3 2 Usage 5 2.1 Usage app................................................ 5 3 Contributing 9 4 Source code and contacts 11 4.1 Repository and bugs........................................... 11 4.2 Contacts................................................. 11 i

ii

django-amp-tools Documentation, Release latest django-amp-tools ( amp_tools ) provides a simple way to work with Accelerated mobile pages (AMP) in django and gives you tools at your hand to render some different templates to deliver an AMP version of your site to the user. The idea (from django-mobile app) is to keep your views exactly the same but to transparently interchange the templates used to render a response. This is done in two steps: 1. A middleware determines the client s preference to view your site. E.g. if he wants to use the AMP or the standart version. 2. The template loader takes then care of choosing the correct templates based on the GET param detected in the middleware. The source code for this app is hosted at https://github.com/shtalinberg/django-amp-tools. Contents: Contents 1

django-amp-tools Documentation, Release latest 2 Contents

CHAPTER 1 Installation Pre-Requirements: django-amp-tools depends on django s sites framework. So before you try to use django-amp-tools make sure that the sites framework is enabled and working. 1. Install django-amp-tools with your favourite python tool, e.g. with easy_install django-amp-tools or pip install django-amp-tools. 2. Add amp_tools to your INSTALLED_APPS setting in the settings.py. 3. Add amp_tools.middleware.ampdetectionmiddleware to end of your MIDDLEWARE_CLASSES setting. 4. Add amp_tools.loader.loader as first item to your loaders list for TEMPLATES setting in settings.py. 3

django-amp-tools Documentation, Release latest 4 Chapter 1. Installation

CHAPTER 2 Usage 2.1 Usage app The concept of django-amp-tools is render amp for your site from save view as desktop version. This makes it possible to provide many possible designs instead of just differentiating between a full desktop experience and one AMP version. After the correct version is somehow chosen by the middlewares, it s assigned to the request.is_amp_detect attribute. You can use this in your views to provide separate logic. <html> <head> <title>my site {% if request.is_amp_detect %}(amp version){% endif %}</title> </head> <body>... </body> </html> You can create own AMP base.html. My example base_amp.html <!doctype html>{% load i18n amp_tags %}{% load static from staticfiles %} <html amp lang="{{ LANGUAGE_CODE }}"> <head> <meta charset="utf-8"> <script async src="https://cdn.ampproject.org/v0.js"></script> <title>bergsoft+</title> {% block amp-link %}{% amp_canonical_link request %}{% endblock %} <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1"> <style amp-custom> {% block amp-custom %} {% include "amp/includes/style_amp_custom.css" %} {% endblock %} </style> {% block amp-ld-json %}{% endblock %} <style amp-boilerplate>body{-webkit-animation:-amp-start 8s steps(1,end) 0s 1 normal both;-moz-an <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome. </head> <body> <header id="#top" class="amp-site-header"> <div> 5

django-amp-tools Documentation, Release latest <a href="{% url 'home_page' %}"> <amp-img src="{% static "images/v-2/logo.png" %}" width="145" height="35" class="amp- {% trans 'Web site development' %} </a> </div> </header> {% block content %} <h1>{% trans "Bergsoft+ company" %}</h1> {% endblock %} <footer class="amp-site-footer"> <div> <h2>{% trans 'Web Development' %}</h2> <p> {% now "Y" %} {{ site.name }}. {% trans "All rights reserved" %}. </p> <a href="#top" class="back-to-top">{% trans "Back to top" %}</a> </div> </footer> </body> </html> In your app template folder (blog, for example) create folder amp for blog detail page blog/tempplates/blog/post_detail.html create AMP version blog/tempplates/blog/amp/post_detail.html with content {% extends "base_amp.html" %} {% load i18n blog_tags %} {% load thumbnail staticfiles %} {% block content %} <article class="amp-post-article"> <header class="amp-post-article-header"> <h1 class="amp-post-title">{{ object.title safe }}</h1> <div class="amp-post-meta amp-post-byline"> {% if post.author.avatar %} <amp-img src="{{ post.author.avatar.url }}" width="24" height="24" layout="fixed"></a {% endif %} <span class="amp-post-author author vcard"><i class="fa fa-user-o"></i> {% trans "Posted </div> <div class="amp-post-meta amp-post-posted-on"> <i class="fa fa-calendar"></i> {{ post.published_at date:"y-m-d" }} </div> </header> {% if object.picture %} <figure class="amp-post-article-featured-image amp-caption"> <amp-img src="{{ object.picture.url }}" width="738" height="430" alt="{{ object.title stripta {#<p class="amp-caption-text">{{ object.picture_caption striptags }}</p>#} </figure> {% endif %} <div class="amp-post-article-content"> {{ post.body_html safe }} </div> <footer class="amp-post-article-footer"> <div class="amp-post-meta amp-post-tax-category"> <i class="fa fa-folder-o"></i> 6 Chapter 2. Usage

django-amp-tools Documentation, Release latest <a href="{{ post.categories.all.0.get_absolute_url }}"> {{ post.categories.all.0 }}</a> </div> {% if post.tags %} <div class="amp-wp-meta amp-wp-tax-tag"> <i class="fa fa-tags"></i> {% for tag in post.tags %} <a href="{{ tag.get_absolute_url }}"> {{ tag }}</a> {% endfor %} </div> {% endif %} </footer> </article> {% endblock %} See result of this code here:: http://bergsoftplus.com/weblog/2016/11/28/internet-bezopasnost-pri-onlajn-pokupkah- 20/?amp-content=amp 2.1.1 Settings Here is a list of settings that are used by django-amp-tools and can be changed in your own settings.py: AMP_TOOLS_GET_PARAMETER The name of GET parameter which check in AMPDetectionMiddleware. Default: amp-content AMP_TOOLS_GET_VALUE The value of GET parameter which check in AMPDetectionMiddleware. select AMP version. Default: amp AMP_TOOLS_TEMPLATE_PREFIX This string will be prefixed to the template names when searching for AMP templates. This is useful if you have many flavours and want to store them in a common subdirectory. Example: from django.template.loader import render_to_string from amp_tools import set_amp_detect set_amp_detect(is_amp_detect=true, request=request) render_to_string('index.html') # will render 'amp/index.html' # now add this to settings.py AMP_TOOLS_TEMPLATE_PREFIX = 'amp-new/' # and try again set_amp_detect(is_amp_detect=true, request=request) render_to_string('index.html') # will render 'amp-new/amp/index.html' Default: (empty string) AMP_TOOLS_TEMPLATE_LOADERS django-mobile s template loader can load templates prefixed with the current flavour. Specify with this setting which loaders are used to load flavoured templates. Default: same as TEMPLATE_LOADERS setting but without amp_tools.loader.loader. 2.1. Usage app 7

django-amp-tools Documentation, Release latest 8 Chapter 2. Usage

CHAPTER 3 Contributing Here are the steps needed to set up a development and testing environment. WARNING This app use git flow for branching strategy and release management. Please, change code and submit all pull requests into branch develop Thanks for contributing, and have fun! 9

django-amp-tools Documentation, Release latest 10 Chapter 3. Contributing

CHAPTER 4 Source code and contacts 4.1 Repository and bugs The source code for this app is hosted on https://github.com/shtalinberg/django-amp-tools. To file bugs and requests, please use https://github.com/shtalinberg/django-amp-tools/issues. 4.2 Contacts Oleksandr Shtalinberg Email: o.shtalinberg at gmail.com 11