Registry / web-framework / django-simple-captcha

django-simple-captcha

JSON →
library0.6.3pypypiunverified

django-simple-captcha is a robust yet easy-to-use Django application for integrating CAPTCHA into forms. It supports various CAPTCHA types including image and audio. Currently at version 0.6.3, it is actively maintained with regular updates to support new Django versions and address user feedback.

pip install django-simple-captcha
INSTALL
IMPORT
SIG · DJANGO-SIMPLE-CAPT
D
django-simple-captcha
web-frameworkpythonv0.6.3
Install
5.0s avg
Import
Disk
87MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.6.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 87.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 5.0s · import 0.000s · 89MB
87MB installed
● package 87MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

CaptchaField
from captcha.fields import CaptchaField
from captcha.fields import CaptchaField
CaptchaTextInput
from captcha.fields import CaptchaTextInput
VERSION
from captcha import VERSION

To integrate django-simple-captcha, first add 'captcha' to your `INSTALLED_APPS` in `settings.py`. Then, include `path('captcha/', include('captcha.urls'))` in your project's `urls.py`. Finally, define a form using `captcha.fields.CaptchaField` and render it in your templates.

import os import django from django.conf import settings # Minimal Django setup for demonstration if not settings.configured: settings.configure( INSTALLED_APPS=['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'captcha'], MIDDLEWARE=[ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', ], ROOT_URLCONF='__main__', TEMPLATES=[ { 'BACKEND': 'django.template.backends.django.DjangoTemplates', 'DIRS': [], 'APP_DIRS': True, 'OPTIONS': { 'context_processors': [ 'django.template.context_processors.debug', 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', ], }, }, ], DATABASES={'default': {'ENGINE': 'django.db.backends.sqlite3', 'NAME': ':memory:'}}, SECRET_KEY=os.environ.get('DJANGO_SECRET_KEY', 'a-very-secret-key-for-testing-only'), STATIC_URL='/static/', DEBUG=True ) django.setup() from django import forms from django.http import HttpResponse from django.urls import path, include from django.views.generic import FormView from captcha.fields import CaptchaField class ContactForm(forms.Form): subject = forms.CharField(max_length=100) message = forms.CharField(widget=forms.Textarea) captcha = CaptchaField() class ContactView(FormView): template_name = 'form_template.html' # In a real app, this would be a file form_class = ContactForm success_url = '/success/' def form_valid(self, form): # Process the form data (e.g., send email) print("Form is valid! Subject:", form.cleaned_data['subject']) return super().form_valid(form) def get(self, request, *args, **kwargs): # For quickstart, just render the form without a real template form = self.get_form() html = f""" <form method="post"> <p>{{ form.subject.label_tag }} {{ form.subject }}</p> <p>{{ form.message.label_tag }} {{ form.message }}</p> <p>{{ form.captcha.label_tag }} {{ form.captcha }}</p> <button type="submit">Submit</button> {% csrf_token %} </form> """ return HttpResponse(html.replace('{% csrf_token %}', request.META.get('CSRF_COOKIE', ''))) def post(self, request, *args, **kwargs): form = self.get_form() if form.is_valid(): return self.form_valid(form) else: return HttpResponse("Form invalid! " + str(form.errors)) urlpatterns = [ path('', ContactView.as_view(), name='contact'), path('captcha/', include('captcha.urls')), path('success/', lambda request: HttpResponse('Form submitted successfully! CAPTCHA was valid.')), ] # To run this minimal example (requires a test runner or manual URL dispatch) # from django.urls import resolve # from django.test import RequestFactory # # factory = RequestFactory() # # # Test GET request # request = factory.get('/') # response = resolve('/').func(request) # print("\nGET Response:", response.status_code, response.content.decode()[:200], "...") # # # Test POST request (replace with actual CAPTCHA values from GET request if needed) # # This part is tricky to automate without actually solving the captcha. # # You would typically submit a solved captcha value. # # Example POST data, assuming 'captcha_0' is the key for the hash, 'captcha_1' for the response: # # post_data = {'subject': 'Test Subject', 'message': 'Test Message', 'captcha_0': 'hash_value', 'captcha_1': 'solved_text'} # # request = factory.post('/', post_data) # # response = resolve('/').func(request) # # print("\nPOST Response:", response.status_code, response.content.decode()[:200], "...") print("Setup complete. You would normally run this via `manage.py runserver`.") print("To access the form, configure your Django project's urls.py with `path('captcha/', include('captcha.urls'))` and `path('', views.ContactView.as_view())`")
Debug
Known issues
gotchaEnsure 'captcha' is added to your `INSTALLED_APPS` and `path('captcha/', include('captcha.urls'))` is configured in your project's `urls.py`. Without these, CAPTCHA images or forms will not render correctly, leading to `NoReverseMatch` errors or missing images.
fix
Add 'captcha' to `INSTALLED_APPS` in `settings.py` and `path('captcha/', include('captcha.urls'))` to your project's `urls.py`.
affects: All versions
gotchaBy default, the CAPTCHA image relies on Django's static files system. If your static files are not correctly configured (especially in production), the CAPTCHA image might not appear. Ensure `STATIC_URL` and `STATIC_ROOT` are properly set and static files are collected.
fix
Verify Django's static files configuration. Run `python manage.py collectstatic` in production and ensure `STATIC_URL` is accessible. In development, `DEBUG = True` generally handles serving static files automatically.
affects: All versions
deprecatedOlder versions of django-simple-captcha (pre-0.6.1) could leave temporary audio files, potentially filling up disk space. While fixed in 0.6.1, users on older versions should consider upgrading or implementing custom cleanup.
fix
Upgrade to version 0.6.1 or newer (`pip install --upgrade django-simple-captcha`). If upgrading is not immediately possible, implement a periodic task to clean up temporary files (e.g., in `os.tempdir`).
affects: <0.6.1
gotchaVersion 0.6.2 made `djangorestframework` an optional dependency. If you were relying on DRF integration and upgrading from a version before 0.6.2, ensure `djangorestframework` is explicitly installed if you need it, as it might no longer be pulled in automatically.
fix
If using DRF features with django-simple-captcha, explicitly install `djangorestframework`: `pip install djangorestframework`.
affects: >=0.6.2
Upgrade
Version history
0.6.3latest on PyPI · released Dec 7, 2025
Audit
Dependencies
DjangorequiredCore framework dependency for any Django application.
djangorestframeworkoptionalOptional dependency for Django REST Framework integration if DRF API captcha is needed.
Agent activity
29 hits · last 30 days
node
28
OpenAI (training)
1
Resources
django-simple-captcha — pip install django-simple-captcha · libregistry