A collection of reusable Django utilities, middleware and app components.
Project description
django_additional_tools
A collection of reusable Django utilities, middleware and app components.
Requirements
Python 3.10+
Django 4.2+ (or any newer LTS)
Works with WSGI and ASGI projects
Installation
pip install django_additional_tools
Features
Production‑only and development‑only decorators
Production/development template tags
Production/development boolean helpers
CSP nonce middleware
Configurable CSP settings
Production / Development Only
Imagine you are coding a new feature but don´t want it to be available for users yet. But you need to fix bugs etc. the same time so you have to push updates. This library solves this problem: There are different features that make specific code only available in production or development use, specified by django´s very own DEBUG setting.
INSTALLED_APPS += ['django_additional_tools']
Views
Use
from django_additional_tools.django_production_development_only.tags import production_only
@production_only
def my_view(request):
return render(request, 'my_template')
or
from django_additional_tools.django_production_development_only.tags import development_only
@development_only
def my_view(request):
return render(request, 'my_template')
to make a whole view only available in production or development mode.
Templates
Use
{% load production %}
{% if production %}
<h1>You´re in production mode</h1>
{% endif %}
or
{% load development %}
{% if development %}
<h1>You´re in development mode</h1>
{% endif %}
to make a whole view only available in production or development mode.
If-Clauses
Use
from django_additional_tools.django_production_development_only.ifs import production_only
def my_view(request):
if production_only:
print('You´re in production mode')
return render(request, 'my_template')
or
from django_additional_tools.django_production_development_only.ifs import development_only
def my_view(request):
if development_only:
print('You´re in development mode')
return render(request, 'my_template')
Content Security Policy
Add a content security policy to your website to secure it.
MIDDLEWARE += ['django_additional_tools.middleware.generate_csp_nonce_middleware']
# Add your configuration data here, e.g. the allowed script sources
# Your CSP will look like this
csp = (
"default-src 'self'; "
f"script-src 'self' 'nonce-{script_nonce}' {settings.CSP_ALLOWED_SCRIPT_DATA}; "
f"style-src 'self' 'nonce-{style_nonce}' {settings.CSP_ALLOWED_SCRIPT_DATA}; "
f"img-src 'self' {settings.CSP_ALLOWED_IMG_DATA}; "
f"frame-src {settings.CSP_ALLOWED_FRAME_DATA}; "
f"connect-src 'self' {settings.CSP_CONNECT_DATA}; "
f"media-src {settings.CSP_ALLOWED_MEDIA_DATA}"
)
# You can configure CSP_ALLOWED_SCRIPT_DATA etc. in the settings.
License
Copyright © 2026 Paul Hudelmaier
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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 Distributions
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 django_additional_tools-0.1.0-py3-none-any.whl.
File metadata
- Download URL: django_additional_tools-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
74593924464b9e251767e27faf2e5e3d6a41d586bfa7f39d7b94342e0fecb070
|
|
| MD5 |
d090ee151fc7eacde0af967624fad7c7
|
|
| BLAKE2b-256 |
d24e05ca71632513ed73ab870112bf536df0d8b993f83b6da01c061ae74d125a
|