openedx.core.djangoapps.geoinfo package#
Submodules#
openedx.core.djangoapps.geoinfo.api module#
Simple Python API to identify the country of origin of page requests.
- openedx.core.djangoapps.geoinfo.api.country_code_from_ip(ip_addr: str) str#
Return the country code associated with an IP address. Handles both IPv4 and IPv6 addresses.
- Parameters:
ip_addr – The IP address to look up.
- Returns:
A 2-letter country code, or an empty string if lookup failed.
openedx.core.djangoapps.geoinfo.middleware module#
Middleware to identify the country of origin of page requests.
Middleware adds country_code in session.
Usage:
# To enable the Geoinfo feature on a per-view basis, use: decorator django.utils.decorators.decorator_from_middleware(middleware_class)
- class openedx.core.djangoapps.geoinfo.middleware.CountryMiddleware(get_response)#
Bases:
MiddlewareMixinIdentify the country by IP address.
- process_request(request)#
Identify the country by IP address.
Store country code in session.