Skip to main content

A tool to protect formulaire from spam.

Project description

Prune's Captcha

What is it for?

Captcha helps prevent robots from spamming using your forms.

Prerequisites

  • To be installed on a Prune Django project that uses poetry or UV

UV project

Installation

Run the following command in the console:

uv add captcha_prune

Updating the captcha

Don't hesitate to regularly run uv sync --upgrade, as the captcha evolves with time and our practices!

Poetry project

Installation

Run the following command:

poetry add prune_captcha

Updating the captcha

Don't hesitate to regularly run poetry update, as the captcha evolves with time and our practices!

Captcha Integration

Configuration

In settings.py, set the path to the images used for the puzzle:

PUZZLE_IMAGE_STATIC_PATH = "website/images/"

Utilisation

  • GET request (form display)

    • Use create_and_get_puzzle to generate the captcha data.

    • Passes the data into the context under the puzzle variable.

    • Include the component in your template:

      from captcha_prune.utils import create_and_get_puzzle
      
      {% include "captcha_prune/components/captcha.html" %}
      
  • POST request (form submission)

    -   Use verify_captcha to validate the captcha.
    
        ```python
        from captcha_prune.utils import verify_captcha
        ```
    
        ```python
        verify_captcha(request, redirect("/"), redirect("website:contact-page"), form)
        ```
    
    -   No feedback if the captcha is correct.
    
    -   Redirects in case of expired session or incorrect captcha.
    

Example

```python
from django.shortcuts import render, redirect

from django.contrib import messages
from captcha_prune.utils import create_and_get_puzzle, verify_captcha
from .forms import ContactForm

def contact_view(request):
    if request.method == "POST":
        form = ContactForm(request.POST)
        if form.is_valid():
            verify_captcha(
                request,
                redirect("/"),
                redirect("website:contact-page"),
                form
            )
            messages.success(request, "Formulaire soumis avec succès.")
            return redirect("/")
        else:
            puzzle = create_and_get_puzzle(request)
    else:
        form = ContactForm()
        puzzle = create_and_get_puzzle(request)
return render(
    request,
    "website/pages/contact/page.html",
    {"form": form, "puzzle": puzzle},
)

# Available Versions

| Version | Date       | Notes                              |
| ------- | ---------- | ---------------------------------- |
| 1.4.0   | 2025-05-20 | added BaseModel in Captcha, ...    |
| 1.3.0   | 2025-04-30 | deleted start_server, deleted ...  |
| 1.2.0   | 2025-04-30 | fixed prune_captcha command, ...   |
| 1.1.0   | 2025-04-30 | start_server was not a module, ... |
| 1.0.0   | 2025-04-29 | First version of the `captcha` ... |

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

prune_captcha-1.4.0.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

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

prune_captcha-1.4.0-py3-none-any.whl (11.8 kB view details)

Uploaded Python 3

File details

Details for the file prune_captcha-1.4.0.tar.gz.

File metadata

  • Download URL: prune_captcha-1.4.0.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.5.31

File hashes

Hashes for prune_captcha-1.4.0.tar.gz
Algorithm Hash digest
SHA256 fefd7b0e16ffb760a99f821215ff3abc7f09ce6a109207e78e8e6779b3b08626
MD5 4109174fad3f26ac14b5e7eafeeb51c3
BLAKE2b-256 8d64fa53409c38d5f5708030e609e6281afa2ba3d1cd9d194bdb057ecb7e3caf

See more details on using hashes here.

File details

Details for the file prune_captcha-1.4.0-py3-none-any.whl.

File metadata

File hashes

Hashes for prune_captcha-1.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 39aa8fe0c4539810285beba46ce2a65fa3e88c8ed3121ea51dbcaafa540ec4bf
MD5 ab8a3d38c7b8e10af37103a3632de9d7
BLAKE2b-256 633d40e83b9a207e7de1a40949729afd1de1bb0e3d1597e62339b29922329319

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