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.5

Потом следует добавить ‘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.7

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.7
File Size Uploaded Provenance Actions
django-ipgeobase-1.0.7.tar.gz 7.4 kB Without provenance Details for django-ipgeobase-1.0.7.tar.gz

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

Download URL django-ipgeobase-1.0.7.tar.gz
Size 7.4 kB
Tags Source
SHA-256 checksum
How to use checksums
9b4f4e23e60dcdc1be268afb351dae9a53434dafd3f95de759924b2920beca86
BLAKE2b-256 checksum
How to use checksums
a7b319b2caa4f42434070c87f755729b6996b522b84b533ffee12eec50e3fe29
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for django-ipgeobase 1.0.7

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