Skip to main content

django-ipgeobase

django-ipgeobase - это приложение для определения региона (а также широты и долготы) в России по IP в Django

Установка

Проделываем в командной строке

$ git clone git://github.com/satels/django-ipgeobase.git
$ cd django-ipgeobase
$ python setup.py install

Или версионированно

$ pip install django-ipgeobase==1.0.3

Потом следует добавить ‘django_ipgeobase’ в INSTALLED_APPS и выполнить

$ python manage.py syncdb  # Django < 1.7
$ python manage.py migrate django_ipgeobase  # Django >= 1.7

Настройка

Добавить app в settings.py

INSTALLED_APPS = [
    ..
    'django_ipgeobase',
    ..
]

Необязательные параметры (в settings.py):

  • IPGEOBASE_CODING - кодировка этого файла (по-умолчанию windows-1251, можно не менять).

  • IPGEOBASE_SOURCE_URL - ссылка на этот файл на сайте-источнике (по-умолчанию установлено, можно не менять)

  • IPGEOBASE_SEND_MESSAGE_FOR_ERRORS - отправлять ли сообщения об ошибках на почту при обновлении (по-умолчание, True)

Использование

Для получения объекта ipgeobase (для определения региона)

from __future__ import print_function, unicode_literals
from django_ipgeobase.models import IPGeoBase

ip = "212.49.98.48"

ipgeobases = IPGeoBase.objects.by_ip(ip)
if ipgeobases.exists():
    ipgeobase = ipgeobases[0]
    print(ipgeobase.country)  # 'RU' - Страна
    print(ipgeobase.district)  # Округ (для указанного ip - Уральский федеральный округ)
    print(ipgeobase.region)  # Регион (Свердловская область)
    print(ipgeobase.city)  # Населенный пункт (Екатеринбург)
    print(ipgeobase.ip_block)  # IP-блок, в который попали (212.49.96.0 - 212.49.127.255)
    print(ipgeobase.start_ip, ipgeobase.end_ip)  # (3560005632, 3560013823), IP-блок в числовом формате
    print(ipgeobase.latitude, ipgeobase.longitude)  # (56.837814, 60.596844), широта и долгота

Обновления базы

Чтобы обновить базу ipgeobase

$ python manage.py ipgeobase_update

Metadata

Release files for django-ipgeobase 1.0.4

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-ipgeobase 1.0.4
File Size Uploaded Provenance Actions
django-ipgeobase-1.0.4.tar.gz 6.9 kB Without provenance Details for django-ipgeobase-1.0.4.tar.gz

Release files / django-ipgeobase-1.0.4.tar.gz

Download URL django-ipgeobase-1.0.4.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
85524b4ca2189f071246a69407b7f111ef5e7966e4dae7109ef577f2aaccec4a
BLAKE2b-256 checksum
How to use checksums
e1326a5a07559a23f939c7012cdf4d759e7057fd98ed48ee5d5f73e98d045941
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-ipgeobase 1.0.4

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page