Preparing a Mobile Web Solution

All members of our household have different brands of mobile phones/OS:es, which makes developing a mobile webpage very tempting compared to doing an app. If going for a mobile webpage, you still want it to look reasonably well not too far away from an app. JQuery Mobile is javascript client-side library which fulfills this criteria. Components of JQuery mobile not only looks good, they are easy to access in the DOM-model and to setup callbacks for user interaction. There is no need to download and install the library in the Raspberry Pi instead it is possible to rely on a Content Delivery Provider (CDN). Just include a reference to the CDN on the mobile webpage and the library will automatically be downloaded when needed and stored in browser cache.

CherryPy is a full webserver including a server side framework. It was chosen because it is reasonable easy to use, still possible to add things like authentication later on. Install cherrypy on the raspberry pi by:

> pip install cherrypy

It is possible to generate a complete webpage from inside python, but it soon tends to create disorder in the code. It is easier to have static html pages on the file system and only generate dynamic content from the code. How is the static html page merged together with the dynamic content? By the use of a template engine. A template engine makes it possible to insert dynamic data into a page at specific places. How is it one? The template engine parses the page, inserts parameters or executes the python code , and generates the final page as html which sent back to the web-browser. The template engine jinja2 was picked, since jinja2 seemed to have the biggest community of the existing ones (2015). Install jinja2 on the raspberry pi by:

> pip install jinja2

A web application in CherryPy is written as a class containing several methods, and in the __main__ method, the application is instantiated together with the web server. If marked correctly, a method in the class is possible to access directly via a REST API call.


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s