简体   繁体   English

如何在OS X中为Django正确设置GEOIP_PATH?

[英]How to properly set GEOIP_PATH for Django in OS X?

I'm just doing my first steps with Python a Django and I'd like to use it with GeoIP on my Mac. 我只是用Python和Django做我的第一步,我想在我的Mac上使用GeoIP。 I've used Homebrew and pip for installing everything I need, but I haven't figured out how to set path for GeoIP. 我已经使用Homebrew和pip来安装我需要的所有东西,但我还没弄清楚如何为GeoIP设置路径。 So I always get this error: 所以我总是得到这个错误:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Python/2.7/site-packages/django/contrib/gis/geoip/base.py", line 91, in __init__
    if not path: raise GeoIPException('GeoIP path must be provided via parameter or the GEOIP_PATH setting.')
django.contrib.gis.geoip.base.GeoIPException: GeoIP path must be provided via parameter or the GEOIP_PATH setting.

You need the GeoIP data which you can download from MaxMind , and you need to set up GEOIP_PATH in your settings.py module to point to wherever you download that GeoIP data. 您需要可以从MaxMind下载的GeoIP数据,并且需要在settings.py模块中设置GEOIP_PATH以指向您下载GeoIP数据的任何位置。

Your directory structure might not be exactly the same as this, but for me I have 您的目录结构可能与此完全不同,但对我来说,我有

<project directory>
    ...
    geoip
    ...
    <app_directory>
        settings.py
    ...

In my settings.py I have a ROOT_PATH set up to refer to the project directory, so 在我的settings.py中,我设置了一个ROOT_PATH来引用项目目录,所以

GEOIP_PATH = ROOT_PATH + '/geoip'

Download the binary / gzip version of the GeoIP data you need, unzip it and put it in that geoip directory. 下载所需的GeoIP数据的二进制/ gzip版本,解压缩并将其放入该geoip目录中。

与其他Django设置相同:通过项目的settings模块。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM