Note that there are some explanatory texts on larger screens.

plurals
  1. POChange Django Templates Based on User-Agent
    primarykey
    data
    text
    <p>I've made a Django site, but I've drank the Koolaid and I want to make an <em>IPhone</em> version. After putting much thought into I've come up with two options:</p> <ol> <li>Make a whole other site, like i.xxxx.com. Tie it into the same database using Django's sites framework.</li> <li>Find some time of middleware that reads the user-agent, and changes the template directories dynamically.</li> </ol> <p>I'd really prefer option #2, however; I have some reservations, mainly because the Django documentation <a href="http://docs.djangoproject.com/en/dev/topics/settings/" rel="noreferrer">discourages changing settings on the fly</a>. I found a <a href="http://www.djangosnippets.org/snippets/1098/" rel="noreferrer">snippet</a> that would do the what I'd like. My main issue is having it as seamless as possible, I'd like it to be automagic and transparent to the user.</p> <p>Has anyone else come across the same issue? Would anyone care to share about how they've tackled making IPhone versions of Django sites?</p> <p><strong>Update</strong></p> <p>I went with a combination of middleware and tweaking the template call.</p> <p>For the middleware, I used <a href="http://code.google.com/p/minidetector/" rel="noreferrer">minidetector</a>. I like it because it detects a <a href="http://www.youtube.com/watch?v=b6E682C7Jj4" rel="noreferrer">plethora</a> of mobile user-agents. All I have to do is check request.mobile in my views.</p> <p>For the template call tweak:</p> <pre><code> def check_mobile(request, template_name): if request.mobile: return 'mobile-%s'%template_name return template_name </code></pre> <p>I use this for any view that I know I have both versions.</p> <p><strong>TODO:</strong></p> <ul> <li>Figure out how to access <em>request.mobile</em> in an extended version of render_to_response so I don't have to use check_mobile('template_name.html')</li> <li>Using the previous automagically fallback to the regular template if no mobile version exists.</li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload