views:

87

answers:

2

I'd like to deliver special versions of my django site for different (mobile-)browser. What are possible solutions to do this?

+1  A: 

In your view, do smthg like this

def map(request, options=None, longitude=None, latitude = None):
    if 'iPhone' in request.META["HTTP_USER_AGENT"]:
        user_agent = 'iPhone'
    elif 'MSIE' in request.META["HTTP_USER_AGENT"]: 
        user_agent ='MSIE'
    else: user_agent=''
    print user_agent
    return render_to_response('map/map.html', 
        {
            'user_agent': user_agent
        })

and in your template

{% ifnotequal user_agent "iPhone" %}
    {% ifequal user_agent "MSIE" %}
        {% include 'map/map_ie.html' %}
    {% else %}
        {% include 'map/map_default.html' %}
    {% endifequal %}
{% else %}
{% include 'map/map_iphone.html' %}
{% endifnotequal %}
vikingosegundo
I'd like to vote up... but i yet can't
doesn't matter :D Welcome to SO
vikingosegundo
+2  A: 

Seems like this has already been answered here: http://stackoverflow.com/questions/164427/change-django-templates-based-on-user-agent

Matthew Christensen