<tfoot id='GxlSW'></tfoot>
      <i id='GxlSW'><tr id='GxlSW'><dt id='GxlSW'><q id='GxlSW'><span id='GxlSW'><b id='GxlSW'><form id='GxlSW'><ins id='GxlSW'></ins><ul id='GxlSW'></ul><sub id='GxlSW'></sub></form><legend id='GxlSW'></legend><bdo id='GxlSW'><pre id='GxlSW'><center id='GxlSW'></center></pre></bdo></b><th id='GxlSW'></th></span></q></dt></tr></i><div id='GxlSW'><tfoot id='GxlSW'></tfoot><dl id='GxlSW'><fieldset id='GxlSW'></fieldset></dl></div>
      • <bdo id='GxlSW'></bdo><ul id='GxlSW'></ul>

      <small id='GxlSW'></small><noframes id='GxlSW'>

      1. <legend id='GxlSW'><style id='GxlSW'><dir id='GxlSW'><q id='GxlSW'></q></dir></style></legend>

        django 1.4 如何从客户端自动获取用户的时区

        时间:2023-07-03

        <small id='ZxU3q'></small><noframes id='ZxU3q'>

        <legend id='ZxU3q'><style id='ZxU3q'><dir id='ZxU3q'><q id='ZxU3q'></q></dir></style></legend>
          <tbody id='ZxU3q'></tbody>
          • <bdo id='ZxU3q'></bdo><ul id='ZxU3q'></ul>
              <i id='ZxU3q'><tr id='ZxU3q'><dt id='ZxU3q'><q id='ZxU3q'><span id='ZxU3q'><b id='ZxU3q'><form id='ZxU3q'><ins id='ZxU3q'></ins><ul id='ZxU3q'></ul><sub id='ZxU3q'></sub></form><legend id='ZxU3q'></legend><bdo id='ZxU3q'><pre id='ZxU3q'><center id='ZxU3q'></center></pre></bdo></b><th id='ZxU3q'></th></span></q></dt></tr></i><div id='ZxU3q'><tfoot id='ZxU3q'></tfoot><dl id='ZxU3q'><fieldset id='ZxU3q'></fieldset></dl></div>
            • <tfoot id='ZxU3q'></tfoot>

                  本文介绍了django 1.4 如何从客户端自动获取用户的时区的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我想知道是否有办法从客户端自动检索用户的时区.尤其是在登录时.

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

                  我尝试在登录页面中添加这个(使用 auth.login):

                  I tried to add this in the login page (using auth.login):

                  {% get_current_timezone as TIME_ZONE %}
                  

                  然后将其添加到登录表单中

                  and then add this in the login form

                  <input type="hidden" name="next" value="/redirect/?tz={{ TIME_ZONE }}">
                  

                  tz 始终是服务器的时区.

                  but tz is always the timezone of the server.

                  推荐答案

                  来自 文档:

                  选择当前时区

                  当前时区是相当于翻译的当前语言环境.然而,没有相当于 Django 可以使用的 Accept-Language HTTP 标头自动确定用户的时区.相反,Django 提供时区选择功能.使用它们来构建时区对您有意义的选择逻辑.

                  The current time zone is the equivalent of the current locale for translations. However, there's no equivalent of the Accept-Language HTTP header that Django could use to determine the user's time zone automatically. Instead, Django provides time zone selection functions. Use them to build the time zone selection logic that makes sense for you.

                  您可以尝试使用 getTimezoneOffset 功能或尝试做一些 geoip 魔术并按位置计算时区.可能最可靠的方法是直接询问用户并将此信息保存在用户配置文件/会话中.

                  You can try setting timezone cookie via javascript by utilizing getTimezoneOffset function or try to do some geoip magic and figure timezone by location. Probably the most reliable way would be to ask the user directly and save this information in user profile/session.

                  这篇关于django 1.4 如何从客户端自动获取用户的时区的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:Python pytz 时区函数返回一个相差 9 分钟的时区 下一篇:django 1.4 - 无法比较 offset-naive 和 offset-aware 日期时间

                  相关文章

                  1. <i id='ZE5Uw'><tr id='ZE5Uw'><dt id='ZE5Uw'><q id='ZE5Uw'><span id='ZE5Uw'><b id='ZE5Uw'><form id='ZE5Uw'><ins id='ZE5Uw'></ins><ul id='ZE5Uw'></ul><sub id='ZE5Uw'></sub></form><legend id='ZE5Uw'></legend><bdo id='ZE5Uw'><pre id='ZE5Uw'><center id='ZE5Uw'></center></pre></bdo></b><th id='ZE5Uw'></th></span></q></dt></tr></i><div id='ZE5Uw'><tfoot id='ZE5Uw'></tfoot><dl id='ZE5Uw'><fieldset id='ZE5Uw'></fieldset></dl></div>
                      <bdo id='ZE5Uw'></bdo><ul id='ZE5Uw'></ul>
                  2. <legend id='ZE5Uw'><style id='ZE5Uw'><dir id='ZE5Uw'><q id='ZE5Uw'></q></dir></style></legend>

                      <tfoot id='ZE5Uw'></tfoot>

                    1. <small id='ZE5Uw'></small><noframes id='ZE5Uw'>