gpt4 book ai didi

javascript - 自动查找用户位置

转载 作者:行者123 更新时间:2023-11-28 02:27:58 25 4
gpt4 key购买 nike

我正在为我的 Django 应用程序集成 Stripe 支付。付款必填字段之一是国家/地区。我的问题是如何知道用户当前的位置?我不需要 map 。我只想要一个国家/地区名称。

最佳答案

添加一个带有国家/地区下拉列表的表单字段并让用户选择。

您可以使用 geoip 作为第一个猜测,但这应该用作此类下拉列表的默认值,因为用户可能正在使用代理。

编辑:

由于您使用的是 Django,我建议使用随附的电池:https://docs.djangoproject.com/en/dev/ref/contrib/gis/geoip/

我宁愿为此使用外部服务。这会减慢您的网站速度,导致不必要的依赖性。

Django View 的示例代码:

from django.contrib.gis.geoip import GeoIP
g = GeoIP()
c = g.country(request.META['REMOTE_ADDR'])
# c.country_code and c.country_name do now contain
# The data you want. Simply pass it to a template,
# form and/or use it for the stripe API.

关于javascript - 自动查找用户位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14599643/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com