Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django_additional_tools-0.1.1.tar.gz (8.1 kB view details)

Uploaded Source

Built Distribution

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

django_additional_tools-0.1.1-py3-none-any.whl (11.9 kB view details)

Uploaded Python 3

File details

Details for the file django_additional_tools-0.1.1.tar.gz.

File metadata

  • Download URL: django_additional_tools-0.1.1.tar.gz
  • Upload date:
  • Size: 8.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for django_additional_tools-0.1.1.tar.gz
Algorithm Hash digest
SHA256 39dcaa7cdf9ae4a4d57abc81eb688ac1c364c2d5f15cc1dd8bc9a1939512c0ef
MD5 309851f568054758b905ec7b9ba2b612
BLAKE2b-256 bc215e40234a52abd602db6a7876f405d3c654ff65caa9cb324f921f5a24802e

See more details on using hashes here.

File details

Details for the file django_additional_tools-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for django_additional_tools-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0f58d63e5cf6b81397484e18f3699602b34717b1ab8d98cf69558a8df4312683
MD5 f759d8820a2808d86c6f273870e6d617
BLAKE2b-256 c3850ecd2225dcea380f10432b46e45e3031d7193de3cb7b00d99cdd2b78f22d

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