Research
Security News
Malicious npm Package Targets Solana Developers and Hijacks Funds
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
.. 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=develop
This 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 <https://adamcharnock.com/>
, and some great contributors <https://github.com/adamcharnock/django-tz-detect/contributors>
.
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.
Either checkout tz_detect
from GitHub, or install using pip:
.. code-block:: bash
pip install django-tz-detect
Add tz_detect
to your INSTALLED_APPS
:
.. code-block:: python
INSTALLED_APPS += (
'tz_detect',
)
Be sure you have the django.template.context_processors.request
processor
.. code-block:: python
TEMPLATES = [
{
...
'OPTIONS': {
'context_processors': [
...
'django.template.context_processors.request',
],
},
},
]
Update your urls.py
file:
.. code-block:: python
urlpatterns += [
path('tz_detect/', include('tz_detect.urls')),
]
Add the detection template tag to your site, ideally in your base layout just before the </body>
tag:
.. code-block:: html+django
{% load tz_detect %}
{% tz_detect %}
Add TimezoneMiddleware
to MIDDLEWARE
:
.. code-block:: python
import django
MIDDLEWARE += (
'tz_detect.middleware.TimezoneMiddleware',
)
if django.VERSION < (1, 10):
MIDDLEWARE_CLASSES += (
'tz_detect.middleware.TimezoneMiddleware',
)
(Optional) Configure the countries in which your app will be most commonly used:
.. code-block:: python
# These countries will be prioritized in the search
# for a matching timezone. Consider putting your
# app's most popular countries first.
# Defaults to the top Internet using countries.
TZ_DETECT_COUNTRIES = ('CN', 'US', 'IN', 'JP', 'BR', 'RU', 'DE', 'FR', 'GB')
Please see example
application. This application is used to manually
test the functionalities of this package. This also serves as a good
example.
You need only Django 1.8 or above to run that. It might run on older versions but that is not tested.
FAQs
Automatic user timezone detection for django
We found that django-tz-detect demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 3 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
A malicious npm package targets Solana developers, rerouting funds in 2% of transactions to a hardcoded address.
Security News
Research
Socket researchers have discovered malicious npm packages targeting crypto developers, stealing credentials and wallet data using spyware delivered through typosquats of popular cryptographic libraries.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.