Skip to main content

django-formguard

Invisible form protection for Django. A pluggable check pipeline that catches bots without any user interaction.

How It Works

FormGuard runs a series of checks against each form submission:

  1. Field trap - hidden honeypot field that bots fill in
  2. Token - signed timestamp that catches fast or tampered submissions
  3. JS challenge - nonce computation that requires JavaScript execution
  4. Interaction proof - detects real user input (accessible to screen readers)

All checks are invisible to real users. Check failures are handled as standard form validation errors, with customizable failure handling for honeypot-style silent rejection.

FormGuard is extensible. Cloudflare Turnstile is available as a contrib check, and you can write your own.

Installation

pip install django-formguard

Add 'formguard' to your INSTALLED_APPS:

INSTALLED_APPS = [
    ...
    'formguard',
]

Quick Start

1. Set up your form

Add GuardedFormMixin to your form.

from django import forms
from formguard.conf import default_checks
from formguard.forms import GuardedFormMixin

class ContactForm(GuardedFormMixin, forms.Form):
    guard_checks = default_checks(exclude=['formguard.checks.InteractionCheck'])

    name = forms.CharField()
    email = forms.EmailField()
    message = forms.CharField(widget=forms.Textarea)

default_checks() returns the built-in check list. Use include and exclude to customize it, or omit guard_checks entirely to use all defaults.

2. Set up your template

Include {{ form.media }} in your <head> so the honeypot CSS and JS checks load.

<head>
    {{ form.media }}
</head>
<body>
    <form method="post">
        {% csrf_token %}
        {{ form }}
        <button type="submit">Send</button>
    </form>
</body>

If you render fields manually, include {{ form.guard_fields }} to add the FormGuard fields.

3. Check submissions in your view

Guard checks run inside is_valid(), so your view uses standard Django patterns.

Class-based views - use GuardedFormViewMixin:

from django.views.generic import FormView
from formguard.views import GuardedFormViewMixin

class ContactView(GuardedFormViewMixin, FormView):
    form_class = ContactForm
    template_name = 'contact.html'
    success_url = '/thanks/'

    def form_valid(self, form):
        send_email(form.cleaned_data)
        return super().form_valid(form)

If a check fails, the form returns an error message. To silently redirect bots to a fake success page instead, see Failure Handling.

Function-based views - see Function-Based Views

Settings

All settings are optional. Defaults work out of the box. All four built-in checks are enabled by default.

# add a custom check alongside the builtins
from formguard.conf import BUILTINS
FORMGUARD_CHECKS = BUILTINS + [
    'myapp.checks.TurnstileCheck',
]

# tune the built-in checks
FORMGUARD_FIELD_TRAP_FIELD_NAME = 'website'  # default
FORMGUARD_TOKEN_MIN_SECONDS = 3              # default
FORMGUARD_TOKEN_MAX_SECONDS = 3600           # default

Further Reading

CSP Compatibility

FormGuard uses external static files for CSS and JS (no inline styles or scripts), so it works with Content Security Policy out of the box when 'self' is in your script-src and style-src.

For strict nonce-based CSP policies, use django-csp-helpers to add nonces to the {{ form.media }} output.

License

This software is released under the MIT license.

Copyright (c) 2026 Luke Rogers

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.

Release files for django-formguard 0.10.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-formguard 0.10.0
File Size Uploaded
django_formguard-0.10.0.tar.gz 51.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-formguard 0.10.0
File Interpreter ABI Platform
django_formguard-0.10.0-py3-none-any.whl Python 3 none any Details

Total release size: 68.6 kB

Release files / django_formguard-0.10.0.tar.gz

Download URL django_formguard-0.10.0.tar.gz
Size 51.1 kB
Tags Source
SHA-256 checksum
How to use checksums
42710245c5ee12d383470ea219ba0fb4704eaf5d2db7429c48a81f5a682d735f
BLAKE2b-256 checksum
How to use checksums
2f17044065369014cf36a69d307d1b48d6970491cebe4b25e8cc63a45ff4de81
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release files / django_formguard-0.10.0-py3-none-any.whl

Download URL django_formguard-0.10.0-py3-none-any.whl
Size 17.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da24d5ae1327e8ebf803cfee45fa88fc0ca0c4c3b0342769733eced5cf4fff09
BLAKE2b-256 checksum
How to use checksums
ec51ab3710605105d67eba573b2cf3d1b96877636c6e1c6560e8ef1384037e26
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Aug 20, 2026.

Transparency log

Release history Release notifications | RSS feed

0.11.0

2 release files

This release

0.10.0 This release

2 release files

0.9.3

2 release files

0.9.2

2 release files

0.9.1

2 release files

0.9.0

2 release files

0.8.3

2 release files

0.8.2

2 release files

0.8.1

2 release files

0.8.0

2 release files

0.7.1

2 release files

0.7.0

2 release files

0.6.0

2 release files

0.5.0

2 release files

0.4.0

2 release files

0.3.0

2 release files

0.2.1

2 release files

0.2.0

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page