Skip to main content

Django app introducing a Context Processor that adds users location information to the context.

Project description

Django app introducing a Context Processor that adds users location information to the context.

To activate, add country_block.context_processors.addgeoip to your CONTEXT_MODIFIERS. This will give you a user_country variable in your context and a country variable in the user’s session with the user’s 2 character ISO country code, and an in_country boolean set to True is the country matches one of the allowed countries.

Local Settings options

LOCATION : a unique 2 char string that identifies the server’s location

COUNTRY_BLOCK_DEBUG_COUNTRY : sets the user_country equal to this value for all users, letting you test as if you are in this country. False by default.

COUNTRY_BLOCK_DEBUG_REGION : sets the region_code equal to this value for all users, letting you test as if you are in this region. False by default.

Database Settings options (country_block.Settings model)

location : This is a unique 2 char value that corresponds to the LOCATION value in the local settings

free_geo_ip_enabled : Use the freegeoip.net to determine the geography of the user’s IP

free_geo_ip_timeout : freegeoip.net request timeout in seconds (default is 2 seconds)

maxmind_enabled : Use the https://geoip.maxmind.com/a service to determine the geography of the user’s IP. If this is True and free_geo_ip_enabled is also True, the context processor will try the freegeoip.net service first and will only try the Maxmind service if freegeoip.net fails.

maxmind_timeout : maxmind.com request timeout in seconds (default is 6 seconds)

maxmind_local_db_enabled : Use a local Maxmind database instead of the https://geoip.maxmind.com/a service. Must also have maxmind_enabled set to True.

allowed_countries : A M2M relationship of all Countrys that are allowed for the server’s location

staff_user_country : The Country that all django staff users will be assigned

local_ip_user_country : The Country that all local IP users will be assigned

maxmind_license_key : The license key for the Maxmind service. A value is required if maxmind_enabled is True and maxmind_local_db_enabled is False. This gets sent over as the ‘l’ parameter in the payload to the https://geoip.maxmind.com/a service.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-country-blocker-1.1.11.tar.gz (10.4 kB view details)

Uploaded Source

File details

Details for the file django-country-blocker-1.1.11.tar.gz.

File metadata

File hashes

Hashes for django-country-blocker-1.1.11.tar.gz
Algorithm Hash digest
SHA256 c3947b78329fcf3f7efcf60fafa08a2dcb3153b30b3c14394cc79c2d6d7e0beb
MD5 17561d59b9a61c35438d0d75992e302d
BLAKE2b-256 b5df0284f3b5c1a6138f38ebe7719a72661f4c4ad3c27dd987760c5e5107947e

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page