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
- Add to
INSTALLED_APPSin your Django settings:
INSTALLED_APPS = [
# ...
"django.contrib.sites",
"gateway_defender",
]
- Add the middleware (required for multi-site support):
MIDDLEWARE = [
# ...
"django.contrib.sites.middleware.CurrentSiteMiddleware",
]
- Include the URLs in your project
urls.py:
from django.urls import include, path
urlpatterns = [
path("", include("gateway_defender.urls")),
]
- 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.
- Run migrations:
python manage.py migrate
- Routes provided by the app:
GET /— login page (usesgateway_defender/gateway.html)GET /portal/— protected portal pageGET /logout/— logout and redirect toindex
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.
- Create a Site in the admin panel for each domain you want to support (e.g.,
localhost:8000in development, or your production domain). - 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.models—AuthToggle,PassPhrasegateway_defender.views—Gateway(login view) andEndSession(logout view)gateway_defender.urls— URL patterns included abovegateway_defender.custom_decorator—protected_redirectdecoratorgateway_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:
- Update
pyproject.tomlversion and metadata. - Build with
python -m build. - 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file gateway_defender-0.2.2.tar.gz.
File metadata
- Download URL: gateway_defender-0.2.2.tar.gz
- Upload date:
- Size: 93.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7cbf4b63cb162c360d1f139aeae6c44500689b1183e3ad47be32df27907800b3
|
|
| MD5 |
d76926013d518a8f2dea39efeda03dd5
|
|
| BLAKE2b-256 |
df87ea72954824a7ab1aea4bbda446721a0f7751b8a0ab2fdbe2a5ed53a3d13c
|
File details
Details for the file gateway_defender-0.2.2-py3-none-any.whl.
File metadata
- Download URL: gateway_defender-0.2.2-py3-none-any.whl
- Upload date:
- Size: 114.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ac8bab12b79adeff3a2746526474876555453e2fee7ada43a168379fb663e1e6
|
|
| MD5 |
a1212a1813e95b17c78ef4d563986b47
|
|
| BLAKE2b-256 |
a79d4d03ff512693e3f759bcea68b5f1d9ff0dd20fdb633d9b0afdcae1673db8
|