Re: HTML5 Offline apps with Django 1.4

449 views
Skip to first unread message

Russell Keith-Magee

unread,
Feb 21, 2013, 6:41:50 PM2/21/13
to django...@googlegroups.com


On Thu, Feb 21, 2013 at 3:38 PM, Ranjith Chaz <ranj...@gmail.com> wrote:
Trying to implement offline feature of HTML5.  Deployed in apache2.2 with mod_wsgi plugin.
It works as expected (i.e., loads the cached page when offline) in chrome, Opera (using window.openDatabase) and other desktop browsers. However it doesn't work in Android 2.x, iPhone default browsers. Strangely, it works with Android 4.0 browser!!
Here is the code:

views.py:
def offlineApp(request):
    t = get_template('index.html')
    html = t.render(Context({'MEDIA_URL':'http://myDomain.com/site_media/'}))
    return HttpResponse(html)

Is it required to use any specific module/middleware to handle text/manifest in django ?
No - you just have to return a response that sets the content type:
    return HttpResponse(html, content_type='text/cache-manifest')
Yours,
Russ Magee %-)

Ranjith Chaz

unread,
Feb 25, 2013, 9:34:35 PM2/25/13
to django...@googlegroups.com
Thanks for the reply, Russell. I had tried it already. What I get when I do this is, the html source instead of the web page. That is, the complete html code gets printed out in the browser and it happens in all browsers irrespective of mobile, desktop.


On Thursday, February 21, 2013 1:08:16 PM UTC+5:30, Ranjith Chaz wrote:
Trying to implement offline feature of HTML5.  Deployed in apache2.2 with mod_wsgi plugin.
It works as expected (i.e., loads the cached page when offline) in chrome, Opera (using window.openDatabase) and other desktop browsers. However it doesn't work in Android 2.x, iPhone default browsers. Strangely, it works with Android 4.0 browser!!
Here is the code:

HTML
<!DOCTYPE HTML>
    <html manifest="{{MEDIA_URL}}cache.manifest">
       <head>
          <meta charset="utf-8">      
          <title>MyHomeStuff</title>      
          <script type="text/javascript" src="{{MEDIA_URL}}MyHomeStuff.js" ></script>
          <script></script>
       </head>
       <body>
         .............
       </body>
    </html>

Apache conf\mime.types text/cache-manifest manifest


\Python27\Lib\mimetypes.py Added '.manifest': 'text/cache-manifest', into types_map dict

(With the above addition to mimetypes.py, it started working for android 4.0)


cache.manifest CACHE MANIFEST
CACHE: index.html MyHomeStuff.js


views.py:

def offlineApp(request):
    t = get_template('index.html')
    html = t.render(Context({'MEDIA_URL':'http://myDomain.com/site_media/'}))
    return HttpResponse(html)

Is it required to use any specific module/middleware to handle text/manifest in django ?
Any help is appreciated. Already spent a lot of time on this!


Russell Keith-Magee

unread,
Mar 1, 2013, 1:44:33 AM3/1/13
to django...@googlegroups.com
Hi Ranjith,

Perhaps I've confused things here -- when you're serving offline HTML5, you need to serve (at least) 2 pages -- a page with html, and a *completely separate* second page containing the manifest. The manifest file has a content type of text/cache-manifest; your HTML is served with a normal text/html content type. 

From what you describe, it sounds like you're just serving the HTML as text/cache-manifest.

Yours,
Russ Magee %-)

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users...@googlegroups.com.
To post to this group, send email to django...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.
 
 

Reply all
Reply to author
Forward
0 new messages