django-geoip2-extras
作用: 直接在 request那边增加了一个geo_data
request.geo_data.country_name
配置方法,参考主页
https://pypi.org/project/django-geoip2-extras/
pip install django-geoip2-extras
MIDDLEWARE = ( ..., 'django.contrib.sessions.middleware.SessionMiddleware', 'geoip2_extras.middleware.GeoIP2Middleware', ... )
# settings.py GEOIP_PATH = os.path.dirname(__file__)
django.contrib.gis.geoip2
作用, https://github.com/maxmind/GeoIP2-python 的封装,开源主页是这个
https://geoip2.readthedocs.io/en/latest/
使用方法:参考下面链接
https://docs.djangoproject.com/en/3.0/ref/contrib/gis/geoip2/
下载GeoLite2-City数据库,放到项目目录下
设置 GEOIP_PATH
这个配置就可以,不用设置middleware
>>> from django.contrib.gis.geoip2 import GeoIP2 >>> g = GeoIP2() >>> g.country('google.com') {'country_code': 'US', 'country_name': 'United States'} >>> g.city('72.14.207.99') {'city': 'Mountain View',
.sqlite3版本问题
https://stackoverflow.com/questions/55674176/django-cant-find-new-sqlite-version-sqlite-3-8-3-or-later-is-required-found
django 2.2 need sqlite version >= 3.8.3
升级之后发现sqlite3不兼容
packages/django/db/backends/sqlite3/base.py", line 63, in check_sqlite_version raise ImproperlyConfigured('SQLite 3.8.3 or later is required (found %s).' % Database.sqlite_version) django.core.exceptions.ImproperlyConfigured: SQLite 3.8.3 or later is required
wget https://www.sqlite.org/2019/sqlite-autoconf-3270100.tar.gz
tar xvfz sqlite-autoconf-3270100.tar.gz
构建并安装
cd sqlite-autoconf-3270100
./configure
make install
ldconfig
发现 SQLite header and source version mismatch 错误
原来是系统原来有
apt-get remove
重新
make install
ldconfig
测试一下:
test1 :
sqlite3 --version
should be your version
test2:
$python
>>> import sqlite3
>>> sqlite3.sqlite_version