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/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.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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file prune_captcha-1.9.0.tar.gz.
File metadata
- Download URL: prune_captcha-1.9.0.tar.gz
- Upload date:
- Size: 9.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6617eaa035c4d467b44582c3fa57a839752b458446ac0282db7d12da7e8b3284
|
|
| MD5 |
d5fa15c2f0b600bdef5324b6e07eb1dc
|
|
| BLAKE2b-256 |
c932c87704c2a0e7c704c31e0b867ca4bb21efdd7e8ef7deeae2aa7d1c9dd686
|
File details
Details for the file prune_captcha-1.9.0-py3-none-any.whl.
File metadata
- Download URL: prune_captcha-1.9.0-py3-none-any.whl
- Upload date:
- Size: 12.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.5.31
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
899103995f9df56d57ecf0d0677e4e5f864f7aaa9671714b270689d4eff80560
|
|
| MD5 |
c72af1275f0bde15fed80a07f8807043
|
|
| BLAKE2b-256 |
df0f2dede58efe700ea81dbad52d37bc478e817e086791646951f19548404d9b
|