Go mobile on Django
Try it out in almost 5 mins, It's kinda easy:
$ pip install minidetector
Install it on your Django project, settings.py:
MIDDLEWARE_CLASSES = (
[...]
'minidetector.Middleware'
)
[...]
INSTALLED_APPS = (
[...]
'minidetector',
)
And lastly you can use it in a function view:
def index(request, template_name='index.html'):
if request.mobile:
template_name='mobile/index.html'
Or in a Class Based View:
class index(CreateView):
template_name = "index.html"
context_object_name = "whatever"
def get_context_data(self, **kwargs):
if self.request.mobile:
self.template_name='mobile/index.html'
And that's all folks!
Written by Oscar M.
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Python
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#