Skip to main content
# Djaptcha

Djaptcha is a Django plugin that implements the `captcha` python package by `lepture`. It is designed to store user sessions in the database and generate random captcha images based on these sessions.

## Installation

If you haven't already, `pip install captcha` and then use the following to install `djaptcha`:

```bash
$ pip install djaptcha
```

Now add `djaptcha` to the list of installed plugins in your Django app.

```python
INSTALLED_APPS = [
...
'djaptcha',
...
]
```

*__Note__: You must have sessions enabled and configured in your django app to use this plugin. You also must have configured a database. End users must have cookies enabled in their browser to be able to generate captcha images.*

Finally, run `python manage.py make_migrations` and `python manage.py migrate` to create the djaptcha database models.

## Settings

It's recommended that you change the following settings to suit your specific project needs:
```python
# These are the default values
DJAPTCHA_MAX_TRIES = 10 # Maximum amount of tries before user can't generate new captchas
DJAPTCHA_LENGTH = 6 # Length of the captcha (example: 'F7W8MG' has a length of 6)
DJAPTCHA_CHARACTERS = 'ABCEFGHJKLMNPRSTUVWXYZ' # Characters allowed in the captcha
DJAPTCHA_URL = STATIC_URL + 'captcha/' # The URL that end users can access captcha images at
DJAPTCHA_DIR = 'static/captcha/' # The local directory your captcha images should be stored in
DJAPTCHA_EXPIRY = 5 # Length in minutes before the captcha and image are deleted
DJAPTCHA_COOKIES_TEMPLATE = 'djaptcha/cookies.html' # The template that tells users to enable cookies
```

## Usage

To add a captcha field to your form you need to follow these steps:

1. Add the `CaptchaMixin` to your View class. *`CaptchaMixin` should be on the far left to ensure it's methods have priority*
```python
from djaptcha.views import CaptchaMixin

class MyView(CaptchaMixin, FormView):
form_class = MyForm
# View logic here
```

2. Add the `CaptchaForm` to your Form class. *`CaptchaForm` should be on the far left to ensure the captcha is validated before any other data.*
```python
from djaptcha.forms import CaptchaForm

class MyForm(CaptchaForm, Form)
# Form fields and logic here.
pass
```

3. Djaptcha also provides some context variables to use in your views. You can use them like so in your form templates:
```html
<!--
captcha_refresh_link : a path to the url that will refresh the captcha image
captcha_retries : the number of retries the user has left
-->
<form method="post">
{% csrf_token %}
{{ form.as_p }}
<p><a href="{{ captcha_refresh_link }}">Refresh</a></p>
<p>{{ captcha_retries }} retries left.</p>
<button type="submit">Submit</button>
</form>
```


Metadata

Release files for djaptcha 0.0.1

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

Source distribution (sdist)

Source distribution for djaptcha 0.0.1
File Size Uploaded
djaptcha-0.0.1.tar.gz 6.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for djaptcha 0.0.1
File Interpreter ABI Platform
djaptcha-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 14.9 kB

Release files / djaptcha-0.0.1.tar.gz

Download URL djaptcha-0.0.1.tar.gz
Size 6.4 kB
Tags Source
SHA-256 checksum
How to use checksums
a155a5760cce3541afe08237893b1e7886fdd12d89c77312fcbee164ba4098e2
BLAKE2b-256 checksum
How to use checksums
4a20f2d22b9e212da2076c3effc4168ca89d1035128e39d52666f0c5bcd7699e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release files / djaptcha-0.0.1-py3-none-any.whl

Download URL djaptcha-0.0.1-py3-none-any.whl
Size 8.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2115ae39b13d5c77a2eb4d5b249fb91d1c4385e77f460f6898e3b1962d14e238
BLAKE2b-256 checksum
How to use checksums
4bce9c07de258715b4d2b64ff37b552e07f1371c6e584ed61a733b2a006249bb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.6.7

Release history Release notifications | RSS feed

This release

0.0.1 This release

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