django 1.4 how to automatically get user's timezone from client

前端 未结 5 965
误落风尘
误落风尘 2020-12-01 21:17

I would like to know if there is a way to automatically retrieve user\'s timezone from client. Especially during login.

I tried to add this in the login page (using

5条回答
  •  臣服心动
    2020-12-01 21:48

    There is a nice APP for django to activate timezone https://pypi.python.org/pypi/django-visitor-information-middleware/0.1.0. Which having two middleware

    TimezoneMiddleware

    The middleware activates a timezone for an authenticated user.

    VisitorInformationMiddleware

    This middleware adds the following keys to the request.visitor dictionary:

    country - country the visitor is based in.

    city - city the visitor is based in

    location.timezone - timezone used in the location visitor is based in

    location.unit_system - unit system used in the location visitor is based in

    user.timezone - timezone of the currently authenticated user

    user.unit_system - unit system of the currently authenticated user.

    cookie_notice - True if a cookie consent notice should be displayed for the current visitor.

    Note: Location of the user is determined based on the user's IP address.
    

提交回复
热议问题