6👍
or you can use django-user_agents app. really good one. you also get the context in your template – among others important for rendering some ads depending on device
in view
request.user_agent.is_mobile
or in template
{% if request.user_agent.is_mobile %}
Do stuff here...
{% endif %}
0👍
Try extracting the user agent string with
request.META['HTTP_USER_AGENT']
and then using this library to parse that string.
Example
from user_agents import parse
ua_string = request.META['HTTP_USER_AGENT']
user_agent = parse(ua_string)
if user_agent.is_mobile:
...
- [Django]-Unicode-objects must be encoded before hashing
- [Django]-Django – Admin – Inline – 'extra' value based on some condition
- [Django]-Django auto_now behaviour
- [Django]-How to get name of file in request.POST?
- [Django]-Change django form value
0👍
- [Django]-Inspite of setting (null=True, blank=True) for ModelForm field, I get validation error on leaving the field blank
- [Django]-With django-filter, is there a quick way to support all possible lookups for fields?
- [Django]-Django iterate on static files in template
- [Django]-How to store JWT Token in DB with Django REST Framework
0👍
Yes, you are little wrong. To install django_mobile
with Django 1.9
you should update settings (I’ve described this in the following PR, not merged yet). It works fine for me.
Exactly, you should replace TEMPLATE_LOADERS
with loaders
and TEMPLATE_CONTEXT_PROCESSORS
with context_processors
in TEMPLATES
dictionary. For more about template options, read the docs.
Source:stackexchange.com