Django Nigerians Only is a third party Django application that allows developers to restrict access to their Django applications to only Nigerian users. It can be extended to other countries as well using some very simple steps.
- Django >= 4.1
- geoip2 >= 4.8.0
-
Install Nigerian Only using pip:
pip install django-nigerians-only
-
Add
'nigerian_only'toINSTALLED_APPSin your Django project's settings. -
Add the following to
MIDDLEWAREin your Django project's settings.
MIDDLEWARE = [
...
'nigerian_only.middleware.NigeriansOnlyMiddleware',
]- Set the list of countries to allow users from using the ISBN Alpha-2 code. Country Codes Alpha-2 & Alpha-3
WHITELISTED_COUNTRIES = ["NG"]- Download the GEOIP2 database from MaxMind and set the path in your
settings.py. You can read more on setting up GeoIP for django here.
GEOIP_PATH = "path/to/GeoLite2-Country.mmdb"Once you achieve the above steps, the middleware would restrict access to only users from the whitelisted countries.
You can also checkout this app with a basic setup of the package Django Nigeria only
- The access would not be restricted if any of the above steps is not completed.
- During development, the default ip address is
127.0.0.1, which is not a valid ip address that can be used to determine the country of the user. Therefore, you need to setWHITELISTED_IPSin the settings to allow access to the application during development.
WHITELISTED_IPS = ['127.0.0.1']- To test the middleware, you can use a VPN to change your location to one of the specified countries or use a valid ip address that can be used to determine the country of the user.
Contributions are welcomed and appreciated! Follow these steps to contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Make changes, ensuring to write tests to confirm your changes did not break anything.
- Push the changes to your fork.
- Submit a pull request.
This project is licensed under the MIT License - see the LICENSEfile for details.