Geo IP Installation (On-Premises Database)¶
安装¶
警告
Please note that the installation depends on your computer’s operating system and distribution. We will assume that a Linux operating system is being used.
- 安装`geoip2 <https://pypi.org/project/geoip2/>`__ Python库
pip install geoip2
下载`GeoLite2 City数据库 <https://dev.maxmind.com/geoip/geoip2/geolite2/>`_。你将下载到名为``GeoLite2-City.mmdb``的文件
- 将文件移动到文件夹``/usr/share/GeoIP/``
mv ~/Downloads/GeoLite2-City.mmdb /usr/share/GeoIP/
重启服务器
注解
If you can’t/don’t want to locate the geoip database in /usr/share/GeoIP/
, you can use the
--geoip-db
option of the Odoo command line interface. This option takes the absolute path to
the GeoIP database file and uses it as the GeoIP database. For example:
./odoo-bin --geoip-db= ~/Downloads/GeoLite2-City.mmdb
警告
GeoIP
Python library can also be used. However this version is discontinued since January
1. See GeoLite Legacy databases are now discontinued
How To Test GeoIP Geolocation In Your Odoo Website¶
Go to your website. Open the web page that you want to test
GeoIP
.选择
。在页面添加以下XML:
<h1 class="text-center" t-esc="request.session.get('geoip')"/>
You should end up with a dictionary indicating the location of the IP address.

注解
If the curly braces are empty {}
, it can be for any of the following reasons :
浏览IP地址为本地主机(
127.0.0.1
)或一个局域网(192.168.*.*
)If a reversed proxy is used, make sure to configure it correctly. See
proxy mode
未安装``geoip2``或未找到GeoIP数据库文件
GeoIP数据库无法解析给定的IP地址