A little bit about technologies and task. Website is running on Django as well as mobile version should be too. Mobile version of website should be much simpler than normal version, not so beautiful, but must do own job well: allow users to know about the product, download and access to the documentation.
I decided to use the same django application for both normal and mobile website versions. I found a few different ways to add mobile website, for example: redirect to another django application, replace
TEMPLATE_DIRS
setting with a version that points to mobile templates if user is using mobile browser or just check and use different logic/templates in every view method. As I wanted to have a different structure for mobile website, I decided to go by my own way.Mobile website path should be prefixed with
/m/
rather than be the same or use a different domain name. So, if normal website download page is http://example.com/download/
, then mobile download page should be http://example.com/m/download/
. Django should check every user request whether it's from mobile browser or not using a User-Agent metadata, and if so, redirect to the mobile version of the page. In other words, if user opens a /download/
page from mobile browser, then she will be redirected to the /m/download/
page. But if she opens a /m/download
page, then no redirects happen - just a mobile version of page is returned to user. I've created different templates and views for mobile version of website. Normal version of website has references only to the normal pages and mobile version of website has references only to the mobile pages. This was done to avoid not necessary redirects that could slow down a work with website. Thus, I had a different version of URL patterns for website in project's
urls.py
:As you see,
website.views
are responsible for handling normal website pages, while website.mobile
for handling mobile website pages.Now need to redirect mobile browser users to the mobile version of website. For this purpose, I wrote a custom middleware called
MobileWebsiteMiddleware
. The task of this middleware is to check if user is from a popular mobile platform and needs to be redirected to the mobile version of website. The other responsibility is to redirect users from mobile to the normal version of website in case if request isn't from mobile browser. This is an extract option, that should be disabled while testing.If you'll check the list list of user agent patterns in
MOBI_REG
you wouldn't find neither iPad nor Android. I want to show a "normal" website for tablets. "Android" keyword is used in User Agent for both mobiles and tablets. While Mobile Android browsers pass a User Agent with a "mobile" keyword, but Tablet Android browsers don't do that. Thus, I will have a normal version for desktop and tablets browsers, but mobile version for mobiles and Kindle.Now I have a simple website, that has two different version: one for desktop and tablet browsers and another for mobile browsers. User will be automatically redirected to the right version of website which depends on used device.
In my next post I'm going to tell more about using jQuery Mobile to build a mobile version of website.
No comments:
Post a Comment