Django Simple Captcha

Adi Ramadhan
2 min readJun 2, 2022

--

Django form field with simple captcha. Using django-simple-captcha library.
django-simple-captcha official docs here.

Captcha

Step 1: Preparation, Create Django Project
create virtualenv: virtualenv venv
start virtualenv: venv/Scripts/activate
install Django and Django simple captcha in virtualenv: pip install django==3.2 django-simple-captcha
Create Django: django-admin startproject myproject
Go to myproject folder: cd myproject

Step 2: Create Django Apps and Add Captcha Module
Create apps: python manage.py startapp myapp
Add myapp and captcha module to INSTALLED_APPS in myproject/settings.py

myproject/settings.py

Step 3: Run Migrations: python manage.py migrate

migrate

Step 4: Setup Templates
Create folder templates in myapp

Add template directory in TEMPLATES parameter in myproject/settings.py

Path(BASE_DIR , 'myapp', 'templates'),

Step 5: Create HTML Files in myapp/templates Folder
Create myapp/templates/home.html

myapp/templates/home.html

Step 6: Create Form
Create forms.py in myapp

myapp/forms.py

Step 7: Update views in myapp/views

myapp/views.py

Step 8: Setup URL
Create myapp/urls.py

myapp/urls.py

Update myproject/urls.py

myproject/urls.py

Step 9: Run Server and Testing
Run Server: python manage.py runserver
Testing: http://127.0.0.1:8000

Captcha
log

--

--