{"id":21833105,"url":"https://github.com/null-none/django-useragent","last_synced_at":"2025-10-08T05:32:08.289Z","repository":{"id":146603464,"uuid":"498611967","full_name":"null-none/django-useragent","owner":"null-none","description":"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.","archived":false,"fork":false,"pushed_at":"2022-06-01T06:31:50.000Z","size":17,"stargazers_count":9,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-09-27T12:36:25.553Z","etag":null,"topics":["django","parser","user-agent","useragent"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/null-none.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":"AUTHORS.txt","dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-06-01T06:09:27.000Z","updated_at":"2024-04-22T11:43:06.000Z","dependencies_parsed_at":null,"dependency_job_id":"75f82813-5685-4b99-b417-778d523074ab","html_url":"https://github.com/null-none/django-useragent","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/null-none/django-useragent","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-useragent","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-useragent/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-useragent/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-useragent/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/null-none","download_url":"https://codeload.github.com/null-none/django-useragent/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/null-none%2Fdjango-useragent/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278892195,"owners_count":26063949,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-08T02:00:06.501Z","response_time":56,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","parser","user-agent","useragent"],"created_at":"2024-11-27T19:28:07.554Z","updated_at":"2025-10-08T05:32:08.281Z","avatar_url":"https://github.com/null-none.png","language":"Python","readme":"Django User Agents\n==================\n\nA django package that allows easy identification of visitor's browser, OS and device information,\nincluding whether the visitor uses a mobile phone, tablet or a touch capable device.\n\n\nInstallation\n============\n\n1. Install ``django-useragent``, you'll have to make sure that `user-agents` is installed first::\n\n    pip install django-useragent\n\n2. Configure ``settings.py``:\n\n   .. code-block:: python\n\n    INSTALLED_APPS = (\n        # Other apps...\n        'django_useragent',\n    )\n\n    # Cache backend is optional, but recommended to speed up user agent parsing\n    CACHES = {\n        'default': {\n            'BACKEND': 'django.core.cache.backends.memcached.MemcachedCache',\n            'LOCATION': '127.0.0.1:11211',\n        }\n    }\n\n    # Name of cache backend to cache user agents. If it not specified default\n    # cache alias will be used. Set to `None` to disable caching.\n    USER_AGENTS_CACHE = 'default'\n\nUsage\n=====\n\nMiddleware\n----------\n\nAdd ``UserAgentMiddleware`` in ``settings.py``:\n\n.. code-block:: python\n\n    MIDDLEWARE_CLASSES = (\n        # other middlewares...\n        'django_useragent.middleware.UserAgentMiddleware',\n    )\n\nA ``user_agent`` attribute will now be added to ``request``, which you can use\nin ``views.py``:\n\n.. code-block:: python\n\n    def my_view(request):\n\n        # Let's assume that the visitor uses an iPhone...\n        request.user_agent.is_mobile # returns True\n        request.user_agent.is_tablet # returns False\n        request.user_agent.is_touch_capable # returns True\n        request.user_agent.is_pc # returns False\n        request.user_agent.is_bot # returns False\n\n        # Accessing user agent's browser attributes\n        request.user_agent.browser  # returns Browser(family=u'Mobile Safari', version=(5, 1), version_string='5.1')\n        request.user_agent.browser.family  # returns 'Mobile Safari'\n        request.user_agent.browser.version  # returns (5, 1)\n        request.user_agent.browser.version_string   # returns '5.1'\n\n        # Operating System properties\n        request.user_agent.os  # returns OperatingSystem(family=u'iOS', version=(5, 1), version_string='5.1')\n        request.user_agent.os.family  # returns 'iOS'\n        request.user_agent.os.version  # returns (5, 1)\n        request.user_agent.os.version_string  # returns '5.1'\n\n        # Device properties\n        request.user_agent.device  # returns Device(family='iPhone')\n        request.user_agent.device.family  # returns 'iPhone'\n\nIf you have ``django.core.context_processors.request`` enabled, ``user_agent``\nwill also be available in template through ``request``:\n\n.. code-block:: html+django\n\n    {% if request.user_agent.is_mobile %}\n        Do stuff here...\n    {% endif %}\n\n\nView Usage\n----------\n\n``django-user_agents`` comes with ``get_user_agent`` which takes a single\n``request`` argument and returns a ``UserAgent`` instance. Example usage:\n\n.. code-block:: python\n\n    from django_user_agents.utils import get_user_agent\n\n    def my_view(request):\n        user_agent = get_user_agent(request)\n        if user_agent.is_mobile:\n            # Do stuff here...\n        elif user_agent.is_tablet:\n            # Do other stuff...\n\n\nTemplate Usage\n--------------\n\n``django-useragent`` comes with a few template filters:\n\n* ``is_mobile``\n* ``is_tablet``\n* ``is_touch_capable``\n* ``is_pc``\n* ``is_bot``\n\nYou can use all of these like any other django template filters:\n\n.. code-block:: html+django\n\n    {% load user_agents %}\n\n    {% if request|is_mobile %}\n        Mobile device stuff...\n    {% endif %}\n\n    {% if request|is_tablet %}\n        Tablet stuff...\n    {% endif %}\n\n    {% if request|is_pc %}\n        PC stuff...\n    {% endif %}\n\n    {% if request|is_touch_capable %}\n        Touch capable device stuff...\n    {% endif %}\n\n    {% if request|is_bot %}\n        Bot stuff...\n    {% endif %}\n\n\nYou can find out more about user agent attributes at `here \u003chttps://github.com/selwin/python-user-agents\u003e`_.\n\n\nRunning Tests\n=============\n\n.. code-block:: console\n\n    `which django-admin.py` test django_useragent --settings=django_useragent.tests.settings --pythonpath=.\n\n\nChangelog\n=========\n\n0.5.0\n-----\n* Add support for Django 2.2 to 3.2.\n\n0.4.0\n-----\n* Add support for Django 2.0 to 2.2. Thanks @adamchainz and @joehybird!\n\n0.3.1\n-----\n* Fixed a bug when request have no META attribute\n\n0.3.0\n-----\n* Python 3, thanks to @hwkns!\n\n0.2.2\n-----\n* Fixed a bug that causes cache set/read to fail when user agent is longer than 250 characters\n\n0.2.1\n-----\n* Fixed packaging\n\n0.2.0\n-----\n* Added template filters\n* Added ``get_user_agent`` function in utils.py\n\n0.1.1\n-----\n* Fixed a ``KeyError`` exception in the case of empty ``HTTP_USER_AGENT``\n\n0.1\n---\n* Initial release\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fdjango-useragent","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnull-none%2Fdjango-useragent","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnull-none%2Fdjango-useragent/lists"}