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/static/website/images/"

Utilisation

  • GET request (form display)

    • Use create_captcha_view to generate the captcha data:

      from captcha_prune.views import create_captcha_view
      
      puzzle = create_captcha_view(request)
      
    • Passes the data into the context under the puzzle variable:

      return render(
          request,
          "website/pages/contact/page.html",
          {"form": form, "puzzle": puzzle},
      )
      
    • Include the component in your template:

      {% include "captcha_prune/captcha.html" %}
      
  • POST request (form submission)

    -   Use verify_captcha_view to validate the captcha:
    
        ```python
        from captcha_prune.views import verify_captcha_view
        ```
    
        ```python
        response = verify_captcha_view(request)
        ```
    
    -   True if the captcha is correct, else False.
    
    -   Redirects in case of expired session or incorrect captcha:
    
        ```python
        if response is False:
            return redirect("website:contact-page")
        ```
    

Example

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

Available Versions

Version Date Notes
1.11.0 2025-05-21 removed utils
1.10.0 2025-05-20 fix documentation, removed ...
1.9.0 2025-05-20 puzzle images path fixed
1.8.0 2025-05-20 added migrations
1.7.0 2025-05-20 PUZZLE_IMAGE_STATIC_PATH ...
1.6.0 2025-05-20 added templates
1.5.0 2025-05-20 app config fixed, components ...
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.11.0.tar.gz (9.0 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.11.0-py3-none-any.whl (11.3 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for prune_captcha-1.11.0.tar.gz
Algorithm Hash digest
SHA256 c00874d26675dde2de35eabe564c0a0d1077c341fc7a23680b60b007b4f8d621
MD5 db0407ddbc71a9be0252f768a2fa449f
BLAKE2b-256 2963c89bcb4ffccd18419456e1c153e0c80a63987f5252945793807d024a716d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for prune_captcha-1.11.0-py3-none-any.whl
Algorithm Hash digest
SHA256 4ea0ccdf2dd713ca72c01c6defbfdbc37adbe02359bd612b5b37f5caa7e6f8d7
MD5 d063828ba871952182cd7210b157fc75
BLAKE2b-256 ef7cf124790f76db9c50376438fec588e9fa18bc179a222203b77e296a0d2780

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