Skip to main content

A django package that allows easy identification of visitor's browser, operating system and device information (mobile phone, tablet or has touch capabilities).

Project description

Django User Agents

A django package that allows easy identification of visitor’s browser, OS and device information, including whether the visitor uses a mobile phone, tablet or a touch capable device. Under the hood, it uses user-agents.

How to Use

  1. Install django-user-agents, you’ll have to make sure that user-agents is installed first:

    pip install pyyaml ua-parser user-agents
    pip install django-user-agents
  2. Configure settings.py:

MIDDLEWARE_CLASSES = (
    # other middlewares...
    'django_user_agents.middleware.UserAgentMiddleware',
)

# Cache backend is optional, but recommended to speed up user agent parsing
CACHES = {
    'default': {
        'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',
        'LOCATION': '127.0.0.1:11211',
    }
}
  1. UserAgentMiddleware will add a user_agent attribute to request:

# Let's assume that the visitor uses an iPhone...

request.user_agent.is_mobile # returns True
request.user_agent.is_tablet # returns False
request.user_agent.is_touch_capable # returns True
request.user_agent.is_pc # returns False

# Accessing user agent's browser attributes
request.user_agent.browser  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')
request.user_agent.browser.family  # returns 'Mobile Safari'
request.user_agent.browser.version  # returns (5, 1)
request.user_agent.browser.version_string   # returns '5.1'

# Operating System properties
request.user_agent.os  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')
request.user_agent.os.family  # returns 'iOS'
request.user_agent.os.version  # returns (5, 1)
request.user_agent.os.version_string  # returns '5.1'

# Device properties
request.user_agent.device  # returns Device(family='iPhone')
request.user_agent.device.family  # returns 'iPhone'

You can find out more about user agent attributes at here.

Running Tests

which django-admin.py test django_user_agents –settings=django_user_agents.tests.settings –pythonpath=.

Changelog

0.1

  • Initial release

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-user_agents-0.1.tar.gz (3.5 kB view details)

Uploaded Source

File details

Details for the file django-user_agents-0.1.tar.gz.

File metadata

File hashes

Hashes for django-user_agents-0.1.tar.gz
Algorithm Hash digest
SHA256 31a60eabdd2f7b0a84d1d4d99862859e86a2d1f36299a7adf8d55b0a9f0eead3
MD5 8aa8ecb4596d94038f5cb8ed9aa00e59
BLAKE2b-256 079c4650d40c147dad22491a017d3d74bc6e71dfd2afaea98b811adf8a2a3268

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page