- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
对于我的 Django 应用程序,我试图通过 amdin 存储登录位置的日志。
我创建了一个中间件并尝试使用“django.contrib.gis.utils import GeoIP”来获取地理位置的纬度和经度值。
但是出现如下错误:
/admin/处的 GeoIPException
GeoIP 路径必须是有效的文件或目录。
代码:trackware.py
from django.contrib.gis.utils import GeoIP
from core.models import Log # your simple Log model
def get_ip(request):
xff = request.META.get('HTTP_X_FORWARDED_FOR')
if xff:
return xff.split(',')[0]
return request.META.get('REMOTE_ADDR')
class UserLocationLoggerMiddleware(object):
def process_request(self, request):
if request.user and request.user.is_superuser:
# Only log requests for superusers,
# you can control this by adding a setting
# to track other user types
ip = get_ip(request)
g = GeoIP()
lat,long = g.lat_lon(ip)
Log.objects.create(request.user, ip, lat, long)
我在 settings.py 中所做的更改:
MIDDLEWARE_CLASSES = (
'django.middleware.common.CommonMiddleware',
#custom middleware
'smartDNA.trackware.UserLocationLoggerMiddleware',
)
BASE_DIR = os.path.abspath(os.path.dirname(__file__))
GEOIP_PATH =os.path.join(BASE_DIR, 'geoip')
模型.py:
class Log(models.Model):
user = models.CharField(verbose_name="User",max_length=32)
ip=models.IPAddressField(verbose_name="IP")
lat= models.DecimalField(verbose_name="Lat",max_digits=10,decimal_places=1)
long= models.DecimalField(verbose_name="Long",max_digits=10,decimal_places=1)
在 admin.py 中注册模型:
admin.site.register(Log)
请问我在做什么错误和解决办法....
最佳答案
我遇到了同样的问题,我是这样解决的:
这是我的项目..
> root
> app
settings.py
urls.py
...
> static
> application
> templates
manage.py
1) 下载 GeoLiteCountry 和 GeoLiteCity.dat.gz
2) 在根目录下创建一个名为geoip
的文件夹并将两个文件放入其中。确保两个文件都重命名为 GeoIPCity.dat 和 GeoIP.dat
3) 在设置文件中指定路径 GEOIP_PATH = os.path.join(BASE_DIR, 'geoip')
4)进行测试
python manage.py shell
>>> from django.contrib.gis.geoip import GeoIP
>>> g = GeoIP()
>>> g.city('72.14.207.99')
..
如果它仍然不起作用,请查看 g
实例以找出指向位置:
>>> print g._city_file
/home/foo/root/geoip/GeoIPCity.dat
>>> print g._country_file
/home/foo/root/geoip/GeoIP.dat
*如果您得到一个空字符串,请尝试查找错误。不要尝试通过修改实例 g._city_file=/home/foo/Desktop/GeoIP.0.dat
重新分配路径,这是行不通的!
关于python - 为我的站点设置 geoip 时出错 "GeoIP path must be a valid file or directory",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20853551/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 6 年前。
我发现 MaxMind 的 GeoIP 数据库的准确度是 99.5%(免费)或 99.8%(商业),如他们网站上公布的那样。有人知道 0.5% 和 0.2% 是多少吗? 他们是新分配的 IP 地址,还
我正在尝试使用 MaxMind GeoIP 数据库,我注意到 C API 提供了一堆不同的缓存模式作为 GeoIP_open 的标志。初始化调用。 GEOIP_MEMORY_CACHE GEOIP_C
在安装 geoip 时,我遇到了依赖冲突。我可以安装 geoip-database 和 geoip-database-extra 包,或者 geoip-database-contrib。我没有注意到它
对于我的 Django 应用程序,我试图通过 amdin 存储登录位置的日志。 我创建了一个中间件并尝试使用“django.contrib.gis.utils import GeoIP”来获取地理位置
尝试捆绑具有 gem geoip-c 但得到 Gem::Ext::BuildError: ERROR: Failed to build gem native extension. /Users/dur
如题,我想用golang做geoip,msg是json格式如下 {"type":"big_platform","xrealip":"8.8.8.8","scheme":"http","log_time
地理定位数据库的来源是什么http://www.maxmind.com/得到它的数据?据我了解,像 ARIN 和 RIPE 这样的 IP 注册机构只保存有关分配 IP 范围的公司的信息,因此它必须来自
我制作的一些网站存在垃圾邮件发送者的问题。我已经确保消息在发布之前必须得到批准,但最近情况变得更糟。 我只能看到所有垃圾邮件之间的一个链接。根据 geoiplookup,所有 IP 地址都是,来自中国
我要配置 GeoIP 根据共享服务器中的国家/地区 IP 地址将域重定向到子域。我创建了一个自定义的 php.ini 来导入 geoip.so 然后在我的 index.php 我添加了这段代码: 在
我有一个配置文件是这样的: input { file { path => "/home/kibana/Documents/external_noise.log" type
当事件从Logstash发送到具有默认indexName的elasticsearch时,geoip.location属于geo_point数据类型。由于geoip.location具有geo_poin
目前,我正在使用 Quova,但当用户使用移动网络(而非 WiFi)并在本国境外漫游时,我正在努力寻找/理解 GeoIP(针对国家/地区分辨率)的准确性。 如果设备的 IP 地址是从家庭网络分配的,那
我想知道你是否可以给我一个有效的代码,这样当有人从英国加载网站时,它会将用户重定向到/UK/然后如果他们从美国加载它会转到/US/如果他们'来自欧盟任何地方(英国除外)到/EU/ 我试过这个代码,它只
我安装了 PHP 5.4 和 GeoIP,但我无法让 GeoIP 工作。错误是: fatal error :在第 7 行/var/www/html/geoip/test.php 中调用未定义的函数 g
这是我正在使用的模块:http://wiki.nginx.org/HttpGeoipModule 据我所知,由于它是在 nginx 配置和 uwsgi 上配置的,因此看起来别无选择,只能让它在每个页面
我正在尝试使用 ELK 堆栈创建 GeoIP 数据,它可以在 Kibana 中可视化。 我最近在 Ubuntu Server 14.04 的虚拟实例上安装了 ELK 堆栈(Elastic Search
我在使用 geoip 阻止国家时遇到问题。当我使用我的托管帐户实用程序来阻止国家/地区时,它会在 .htaccess 中创建以下脚本。问题是它似乎不起作用(添加了美国但未被阻止)。 GeoIPEnab
我正在运行Elasticsearch 1.5.2版。 Logstash版本1.5.4。 大多数logstash设置为默认设置: geoip { source => "ipaddress"
这个问题是一个更具体问题的一般版本 asked here .但是,这些答案无法使用。 问题: geoIP数据的原始来源是什么? 许多网站会告诉我我的 IP 在哪里,但它们似乎都在使用来自不到 5 家公
我是一名优秀的程序员,十分优秀!