https://github.com/adamcharnock/django-tz-detect
Easy user timezone detection for Django
https://github.com/adamcharnock/django-tz-detect
Last synced: 10 days ago
JSON representation
Easy user timezone detection for Django
- Host: GitHub
- URL: https://github.com/adamcharnock/django-tz-detect
- Owner: adamcharnock
- License: mit
- Created: 2013-06-19T17:48:49.000Z (almost 12 years ago)
- Default Branch: develop
- Last Pushed: 2024-11-30T08:06:41.000Z (6 months ago)
- Last Synced: 2025-04-25T11:50:55.590Z (30 days ago)
- Language: Python
- Homepage: https://pypi.python.org/pypi/django-tz-detect
- Size: 120 KB
- Stars: 220
- Watchers: 7
- Forks: 40
- Open Issues: 14
-
Metadata Files:
- Readme: README.rst
- Changelog: CHANGES.txt
- Contributing: CONTRIBUTING.md
- License: LICENSE
Awesome Lists containing this project
README
django-tz-detect
================.. image:: https://img.shields.io/pypi/v/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/.. image:: https://img.shields.io/pypi/dm/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/.. image:: https://img.shields.io/github/license/adamcharnock/django-tz-detect.svg
:target: https://pypi.python.org/pypi/django-tz-detect/.. image:: https://coveralls.io/repos/adamcharnock/django-tz-detect/badge.svg?branch=develop
:target: https://coveralls.io/r/adamcharnock/django-tz-detect?branch=developThis app will auto-detect a user's timezone using JavaScript, then
configure Django's timezone localization system accordingly. As a
result, dates shown to users will be in their local timezones.Authored by `Adam Charnock `_ (who is available for freelance/contract work), and some great `contributors `_.
How it works
------------On the first page view you should find that ``tz_detect`` places a
piece of asynchronous JavaScript code into your page using the
template tag you inserted. The script will obtain the user's GMT
offset using ``getTimezoneOffset``, and post it back to Django. The
offset is stored in the user's session and Django's timezone awareness
is configured in the middleware.The JavaScript will not be displayed in future requests.
Installation
------------1. Either checkout ``tz_detect`` from GitHub, or install using pip:
.. code-block:: bash
pip install django-tz-detect
2. Add ``tz_detect`` to your ``INSTALLED_APPS``:
.. code-block:: python
INSTALLED_APPS += (
'tz_detect',
)3. Be sure you have the ``django.template.context_processors.request`` processor
.. code-block:: pythonTEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'django.template.context_processors.request',
],
},
},
]4. Update your ``urls.py`` file:
.. code-block:: python
urlpatterns += [
path('tz_detect/', include('tz_detect.urls')),
]5. Add the detection template tag to your site, ideally in your base layout just before the ``