Skip to main content

Reusable Django app gateway-defender

Project description

gateway-defender

gateway-defender is a small, reusable Django app that provides authentication helpers (login/logout views), a protected portal view, session timeout handling, and packaged templates/static assets. The PyPI distribution name is gateway-defender; the importable Python package is gateway_defender.


Install

Install from PyPI with pip:

pip install gateway-defender

Quick start

  1. Add to INSTALLED_APPS in your Django settings:
INSTALLED_APPS = [
    # ...
    "django.contrib.sites",
    "gateway_defender",
]
  1. Add the middleware (required for multi-site support):
MIDDLEWARE = [
    # ...
    "django.contrib.sites.middleware.CurrentSiteMiddleware",
]
  1. Include the URLs in your project urls.py:
from django.urls import include, path

urlpatterns = [
    path("", include("gateway_defender.urls")),
]
  1. Configure the portal template to render after successful login:
    Add this inside your settings.py
# Defaults to "gateway_defender/portal.html"
GATEWAY_PORTAL_TEMPLATE = "your_app/portal.html"

Ensure the template exists within one of the template directories defined in TEMPLATES in your settings.

  1. Run migrations:
python manage.py migrate
  1. Routes provided by the app:
  • GET / — login page (uses gateway_defender/gateway.html)
  • GET /portal/ — protected portal page
  • GET /logout/ — logout and redirect to index

Multi-site configuration (v0.1.4+)

The app uses Django's Sites framework so you can configure different authentication settings per domain while sharing a single database.

  1. Create a Site in the admin panel for each domain you want to support (e.g., localhost:8000 in development, or your production domain).
  2. In the admin panel, when creating an AuthToggle, assign it to the appropriate Site.

Important: You must have at least one Site configured. Either create the Site record(s) in the admin panel. Without a valid Site, Django's Sites framework can raise a Site.DoesNotExist error when resolving the current site.

If no matching Site is found for the current request, the first AuthToggle entry is used as a fallback.


API / Files included

Key modules included in the package:

  • gateway_defender.modelsAuthToggle, PassPhrase
  • gateway_defender.viewsGateway (login view) and EndSession (logout view)
  • gateway_defender.urls — URL patterns included above
  • gateway_defender.custom_decoratorprotected_redirect decorator
  • gateway_defender/templates/ — packaged templates (gateway_defender/gateway.html, gateway_defender/logged_out.html)
  • gateway_defender/static/ — CSS and images

Refer to module docstrings and the source for details.


Compatibility

  • Python: 3.10 — 3.13
  • Django: >= 4.2 (tested with Django 5.2)

Development

Run tests and linters in your development environment. For local development:

pip install -r requirements-dev.txt  # if you create one
pytest

When preparing a release:

  1. Update pyproject.toml version and metadata.
  2. Build with python -m build.
  3. Upload with twine upload dist/*.

Contributing

Contributions are welcome. Please open issues or PRs and include tests for new behavior. Keep public APIs stable where possible.


License

MIT — see the LICENSE file included in the repository.


Project & PyPI

PyPI package name: gateway-defender
Python package (import): gateway_defender

Update the repository or PyPI URLs here if you host the project on GitHub or another platform.

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

gateway_defender-0.2.1.tar.gz (93.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gateway_defender-0.2.1-py3-none-any.whl (112.3 kB view details)

Uploaded Python 3

File details

Details for the file gateway_defender-0.2.1.tar.gz.

File metadata

  • Download URL: gateway_defender-0.2.1.tar.gz
  • Upload date:
  • Size: 93.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.3

File hashes

Hashes for gateway_defender-0.2.1.tar.gz
Algorithm Hash digest
SHA256 800a7cc1015f27bd997b5fc13a2896a902508a79f615b0a42cc3a53c4c228b88
MD5 c75ac629f405552ad9444853af524518
BLAKE2b-256 85cd4aec80590cc5e6c98389cbb0c3f6ef9678cc841ba8a01988bbc30914d2d1

See more details on using hashes here.

File details

Details for the file gateway_defender-0.2.1-py3-none-any.whl.

File metadata

File hashes

Hashes for gateway_defender-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3291adedc0ce47e0fa420c3ad2a12e4bfb5737a625cff58e1c3713e8e1fb2371
MD5 3cfe9cc98130f8a048a1d59e73fdecae
BLAKE2b-256 61ad8ee7d86640c3764bdf6492a2076f52d52367cdd312d8bddd5eec1d3e4ea9

See more details on using hashes here.

Supported by

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