20
Update:
I just found: http://code.google.com/p/minidetector/
Which seems to do exactly what I want, I’m going to test now. Feel free to tell me i’m wrong!
15
best practice: use minidetector to add the extra info to the request, then use django’s built in request context to pass it to your templates like so.
from django.shortcuts import render_to_response
from django.template import RequestContext
def my_view_on_mobile_and_desktop(request)
.....
render_to_response('regular_template.html',
{'my vars to template':vars},
context_instance=RequestContext(request))
then in your template you are able to introduce stuff like:
<html>
<head>
{% block head %}
<title>blah</title>
{% if request.mobile %}
<link rel="stylesheet" href="{{ MEDIA_URL }}/styles/base-mobile.css">
{% else %}
<link rel="stylesheet" href="{{ MEDIA_URL }}/styles/base-desktop.css">
{% endif %}
</head>
<body>
<div id="navigation">
{% include "_navigation.html" %}
</div>
{% if not request.mobile %}
<div id="sidebar">
<p> sidebar content not fit for mobile </p>
</div>
{% endif %>
<div id="content">
<article>
{% if not request.mobile %}
<aside>
<p> aside content </p>
</aside>
{% endif %}
<p> article content </p>
</aricle>
</div>
</body>
</html>
- [Django]-Update all models at once in Django
- [Django]-How to expire session due to inactivity in Django?
- [Django]-Django class-based view: How do I pass additional parameters to the as_view method?
8
go for the fork of minidetecor called django-mobi, it includes documentation on how to use it.
- [Django]-PyCharm not recognizing Django project imports: from my_app.models import thing
- [Django]-Django – SQL bulk get_or_create possible?
- [Django]-Get the index of an element in a queryset
Source:stackexchange.com