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.

  1. 安装`geoip2 <>`__ Python库
    pip install geoip2
  2. 下载`GeoLite2 City数据库 <>`_。你将下载到名为``GeoLite2-City.mmdb``的文件

  3. 将文件移动到文件夹``/usr/share/GeoIP/``
    mv ~/Downloads/GeoLite2-City.mmdb /usr/share/GeoIP/
  4. 重启服务器


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

  1. Go to your website. Open the web page that you want to test GeoIP.

  2. 选择 自定义 ‣ HTML/CSS/JS编辑器

  3. 在页面添加以下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地址为本地主机(或一个局域网(192.168.*.*)

  • If a reversed proxy is used, make sure to configure it correctly. See proxy mode

  • 未安装``geoip2``或未找到GeoIP数据库文件

  • GeoIP数据库无法解析给定的IP地址