Skip to main content

Django Nigerians Only

Django Nigerians Only is a third-party Django application that restricts access to Django applications to only Nigerian users. It can be extended to other countries with a few simple steps.

Requirements

  • Django >= 4.1
  • geoip2 >= 4.8.0

Installation

  1. Install Nigerian Only using pip:

    pip install django-nigerians-only
    
  2. Add 'nigerian_only' to INSTALLED_APPS in your Django project's settings.py:

    INSTALLED_APPS = [
        ...
        'nigerian_only',
    ]
    
  3. Add the middleware to MIDDLEWARE in settings.py:

    MIDDLEWARE = [
        ...
        'nigerian_only.middleware.NigeriansOnlyMiddleware',
    ]
    
  4. Whitelist allowed countries by setting the list of allowed countries using ISO Alpha-2 country codes. Find Country Codes Alpha-2 & Alpha-3 here.

    WHITELISTED_COUNTRIES = ["NG"]  # Example: "NG" for Nigeria
    
  5. Download the GeoIP2 database from MaxMind and set the path in settings.py. You can read more on setting up GeoIP for Django here.

    GEOIP_PATH = "path/to/GeoLite2-Country.mmdb"
    

Usage

Once the above steps are completed, the middleware will restrict access to users from the whitelisted countries.

  • Example Usage with Middleware: The middleware automatically restricts access for all views.

  • Restrict Access Per View: You can also restrict access on a per-view basis using the whitelisted_country_only decorator:

    from django.http import HttpResponse
    from nigerian_only.decorators import whitelisted_country_only
    
    @whitelisted_country_only
    def restricted_view(request):
        return HttpResponse("This is a restricted view to only whitelisted countries.")
    

Important Notes

  • Access will not be restricted if any of the steps mentioned above is not completed correctly.

  • Development Environment: During development, the default IP address is 127.0.0.1, which cannot determine the user's country. You need to set WHITELISTED_IPS in settings.py to allow access during development:

    WHITELISTED_IPS = ['127.0.0.1']
    
  • Testing: To test the middleware, use a VPN to change your location to one of the specified countries or use a valid IP address to determine the user's country.

Example Project

You can check out this app with a basic setup example of the package here: Django Nigeria Only Example.

Contributing

Contributions are welcome and appreciated! Follow these steps to contribute:

  1. Fork the repository.
  2. Create a new branch for your feature or bug fix.
  3. Make changes and write tests to ensure your changes don't break anything.
  4. Push the changes to your fork.
  5. Submit a pull request.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Developed by Afeez Lawal

Contact Me:


Metadata

Release files for django-nigerians-only 1.0

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-nigerians-only 1.0
File Size Uploaded Provenance Actions
django_nigerians_only-1.0.tar.gz 6.6 kB Without provenance Details for django_nigerians_only-1.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-nigerians-only 1.0
File Interpreter ABI Platform Actions
django_nigerians_only-1.0-py3-none-any.whl Python 3 none any Details for django_nigerians_only-1.0-py3-none-any.whl

Total release size: 14.4 kB

Release files / django_nigerians_only-1.0.tar.gz

Download URL django_nigerians_only-1.0.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
2ea59683ab85965c44b3e49f7e248adde85cc9ea91eccca5da74142129072a13
BLAKE2b-256 checksum
How to use checksums
11a5f4782a835e525511c4866b8c44599a1d63c5175e9a0d71157573dfb363ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.10

Release files / django_nigerians_only-1.0-py3-none-any.whl

Download URL django_nigerians_only-1.0-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
06f3aae37e23fd83c2695fa7d4fb986436bc1becf1079e37b75839e4a58f8491
BLAKE2b-256 checksum
How to use checksums
80e47c80cd382c438cb969709d34b6d07b6044ebcc96ca8cda5eac37ecd645ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.10

Security for django-nigerians-only 1.0

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.

Release history Release notifications | RSS feed

This release

1.0 This release

2 release files No provenance

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