Skip to main content

A smart Django security package to auto-block suspicious traffic

Project description

django-secux - All-in-One Django Security & Optimization

django-secux

Table of Contents

  1. Overview
  2. Features
  3. Installation
  4. Usage
  5. Configuration
  6. Contributing

Overview

django-secux is a comprehensive Django package that combines security protection with performance optimization features, including rate limiting, static file minification, and image compression.

[!Note] v2.0.0 Enhancing the Rate Limit page design

Features

  • Intelligent Rate Limiting: Protects heavy-load pages based on real usage patterns
  • Static File Optimization: Minification for HTML, CSS, JS
  • Fake CDN System: Image compression with on-demand resizing
  • Easy Integration: Simple decorator-based implementation

Installation

pip install django-secux

Add to your Django project:

# settings.py
INSTALLED_APPS = [
    ...
    'django_secux',
]

# For minification support
MIDDLEWARE = [
    ...
    'django_secux.middleware.Minify',
]

Apply migrations:

python manage.py makemigrations django_secux
python manage.py migrate

Usage

Rate Limiting

from django_secux.decorator import ai_ratelimit

@ai_ratelimit()
def protected_view(request):
    return HttpResponse("Protected content")

Fake CDN System

  1. Add to your main urls.py:
from django_secux.views import cdn_serve

urlpatterns = [
    ...
    path('cdn/<path:file_path>', cdn_serve, name='cdn'),
]
  1. Run collectstatic:
python manage.py collectstatic
  1. Use in templates:
<!-- Basic usage -->
<img src="/cdn[ STATIC ]">

<!-- With resizing -->
<img src="/cdn[ STATIC ]?size=250">

Static File Optimization

The package automatically handles:

  • Minification of HTML/CSS/JS
  • Font optimization
  • Image compression (when using Fake CDN)

Configuration

# settings.py

# Security messages
SECUX_MESSAGES = {
    "blocked": "This page is temporarily blocked. Please try again later.",
    "rate_exceeded": "Rate limit exceeded. This page is blocked temporarily.",
}

# Static/media files locations
SECUX_STATIC = [
    STATIC_ROOT,
    *STATICFILES_DIRS,
    os.path.join(BASE_DIR, "media/uploads"),
    os.path.join(BASE_DIR, "protected/images"),
]

Contributing

We welcome contributions! Please report issues or submit pull requests on GitHub.

Key areas for contribution:

  • Additional optimization features
  • Improved rate limiting algorithms
  • Enhanced Fake CDN functionality

This documentation now has clear sections, better organization, and emphasizes the Fake CDN system requirements (collectstatic) while maintaining all the original information in a more professional structure.

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_secux-2.0.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

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

django_secux-2.0.0-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

Details for the file django_secux-2.0.0.tar.gz.

File metadata

  • Download URL: django_secux-2.0.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_secux-2.0.0.tar.gz
Algorithm Hash digest
SHA256 b122be6167e4f7de57f198b8eedefbec7733e3d9cd3ea13a8a37cfe00c1b8b7c
MD5 7c57dd8e1cf62eb110113be1f09cff02
BLAKE2b-256 92c11fe1c9238943f6ca197d6d800ec571f7c22b7796545f049c67f03f6c6f7f

See more details on using hashes here.

File details

Details for the file django_secux-2.0.0-py3-none-any.whl.

File metadata

  • Download URL: django_secux-2.0.0-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for django_secux-2.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 dc1e475830a2fce29e9d4db26e77b20b530ab92a2a46644035e49780159e36b2
MD5 1dcca8f193dd9d4ad473ab114176f2ed
BLAKE2b-256 15248e061ebb427df2f9f31b1aa8c69e6ae1c9bf3e67ae9beb21138f6a919cf0

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