{"id":31729854,"url":"https://github.com/ron4fun/restrict-ip-country","last_synced_at":"2026-05-18T14:34:58.331Z","repository":{"id":144178308,"uuid":"612137781","full_name":"ron4fun/restrict-ip-country","owner":"ron4fun","description":"A reusable Django app for restricting ip addresses and country areas from accessing site.","archived":false,"fork":false,"pushed_at":"2023-03-15T04:17:53.000Z","size":29,"stargazers_count":1,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-09T07:18:55.571Z","etag":null,"topics":["block-ip-country","django","python3","restrict-ip-country"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ron4fun.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2023-03-10T09:27:18.000Z","updated_at":"2024-11-06T00:21:40.000Z","dependencies_parsed_at":null,"dependency_job_id":"a1f891d3-86a0-4f35-bd8f-7a8f9d3f61c1","html_url":"https://github.com/ron4fun/restrict-ip-country","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ron4fun/restrict-ip-country","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ron4fun%2Frestrict-ip-country","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ron4fun%2Frestrict-ip-country/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ron4fun%2Frestrict-ip-country/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ron4fun%2Frestrict-ip-country/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ron4fun","download_url":"https://codeload.github.com/ron4fun/restrict-ip-country/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ron4fun%2Frestrict-ip-country/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":33181145,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-18T09:27:30.708Z","status":"ssl_error","status_checked_at":"2026-05-18T09:27:28.300Z","response_time":71,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["block-ip-country","django","python3","restrict-ip-country"],"created_at":"2025-10-09T07:18:11.586Z","updated_at":"2026-05-18T14:34:58.326Z","avatar_url":"https://github.com/ron4fun.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"Restrict IPs \u0026 Countries \n------------------------\n\n`restrict-ip-country` is a reusable Django app for restricting ip addresses and country areas from accessing site.\n\nRequirements\n------------\n\n* Django \u003e= 3.2\n* geoip2\n\n\n============\nInstallation\n============\n\nAn obvious prerequisite of restrict-ip-country is Django - 3.2 is the\nminimum supported version.\n\n\nInstalling restrict-ip-country\n==============================\n\nDownload and install from http://github.com/ron4fun/restrict-ip-country.git\n\nIf you're using pip__ and a virtual environment, this usually looks like::\n\n    pip install -e git+http://github.com/ron4fun/restrict-ip-country.git#egg=restrict-ip-country\n\n.. __: http://pip.openplans.org/\n\nOr for a manual installation, once you've downloaded the package, unpack it\nand run the ``setup.py`` installation script::\n\n    python setup.py install\n\n\n===========================\nConfiguring GeoIP2 settings\n===========================\n\nEnsure you setup `GeoIP2`, read more here: https://docs.djangoproject.com/en/3.2/ref/contrib/gis/geoip2/\nglobal variables in your ``settings.py``::\n\n    GEOIP_PATH=os.path.join(BASE_DIR, 'data')\n\nA string or pathlib.Path specifying the directory where the GeoIP data files are located. \nThis setting is required.\n\n    GEOIP_CITY='GeoLite2-City.mmdb'\n\nThe basename to use for the GeoIP city data file. Defaults to `GeoLite2-City.mmdb`, \ndownload here: https://git.io/GeoLite2-City.mmdb.\n\n\n=====\nUsage\n=====\n\nFirst, add ``restrict_ip_country`` to your ``INSTALLED_APPS`` in your ``settings.py``.\nRun ``./manage.py migrate`` to install models.\n\n\nConfiguring your project\n========================\n\nIn your Django project's settings module, add restrict_ip_country to your\n``INSTALLED_APPS`` setting::\n    \n    INSTALLED_APPS = (\n        ...\n        'restrict_ip_country',\n    )\n\nFinally, add ``restrict_ip_country.middleware.RestrictIpMiddleware`` to your ``MIDDLEWARE`` in your ``settings.py``, \nensure all configurations are properly done to avoid errors.\n\n\n========\nSettings\n========\n\nFollowing is a list of settings which can be added to your Django settings\nconfiguration. The ``RESTRICT_IP_TEMPLATE_PATH`` is required and other settings \nare optional and the default value is listed for each.\n\n\nUsing RESTRICT_IP_TEMPLATE_PATH\n-------------------------------\n\n* The path where the template to be rendered is located when access is restricted to site,\ndefaults to ``errors/403.html``.\n\n    RESTRICT_IP_TEMPLATE_PATH = \"errors/403.html\"\n\n* Note: if template is not available or found. ``TemplateDoesNotExist`` exception is thrown.\n\n\nUsing RESTRICT_IP_TEMPLATE_CONTEXT_BACKEND\n------------------------------------------\n\nA function when called in your app returns a dictionary, the \ncontext data used in rendering the restricted template::\n\n    RESTRICT_IP_TEMPLATE_CONTEXT_BACKEND = \"your.actual.ContextBackend\"\n\nDefaults to ``None``.\n\n\nUsing RESTRICT_IP_CACHE_TIMEOUT\n-------------------------------\n\nThe time in seconds to cache the database restricted values, \nto minimize un-necessary calls per request especially in times of high traffic::\n\n    RESTRICT_IP_CACHE_TIMEOUT = 300\n\nDefaults to ``300`` seconds. And ``0`` to not cache at all.\n\n\nUsing RESTRICT_IP_BLOCK_NOTFOUND\n--------------------------------\n\nBlock any parsed ip address not found in the ``GEOIP_CITY`` database.\n\n    RESTRICT_IP_BLOCK_NOTFOUND = False\n\nDefaults to ``False``.\n\nNote: you must have at least a restricted ip or country set in your database for it to work. \nThis is for optimization purposes.\n\n\nCommand Extensions\n==================\n\nWith restrict_ip_country in your ``INSTALLED_APPS``, there will be 2 new\n``manage.py`` commands you can run:\n\n* ``get_ip_info`` will get the city information of the given ip address.\n  Use the ``-p``or ``--ip`` option to set the ip address.\n\n* ``get_restrict_config`` will get the restrict-ip-country configs including \n  the restricted ip addresses and countries.\n\n\nIf you use `Windows OS` or alternatives, and find it difficult piping logging infos to output file or setting verbosity level\nUse the ``-f`` or ``--file`` option to set the full path to the logging output file.\nUse the ``-v`` or ``--verbosity`` option to set the verbosity level i.e, {0,1,2,3}.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fron4fun%2Frestrict-ip-country","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fron4fun%2Frestrict-ip-country","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fron4fun%2Frestrict-ip-country/lists"}