Integrating hCaptcha with Django-allauth

Full Stack Developer | Pythonista | Student | Programmer | Tech Enthusiast | Learner | Linux 🖤
Search for a command to run...

Full Stack Developer | Pythonista | Student | Programmer | Tech Enthusiast | Learner | Linux 🖤
No comments yet. Be the first to comment.
The Beginning: Building My First "Real" App Recently, I embarked on building a Splitwise-like expense-splitting app using React Native and Expo. This wasn't just another side project—it was my first proper dive into this tech stack, with React Native...

As AI continues to evolve, one of the limitations of generative AI is its tendency to hallucinate—producing inaccurate or nonsensical outputs, especially when it lacks relevant context. This is where Retrieval-Augmented Generation (RAG) comes in. RAG...

The general perception is that deploying applications on the cloud is complicated, but that is not always true. We have really easy ways to deploy stuff on the cloud as well. So I will be demonstrating how to deploy Django Webpps to Azure easily. Pr...

Linux is known for its flexibility and powerful command-line tools. To make the most out of your Linux system, here are five productivity tools that can enhance your workflow. 1) Zoxide (z) So you might be wondering what exactly is zoxide ? According...

In the last blog, we discussed how can we use Django templating to the fullest. In this blog, we will discuss how can we use databases and handle our data in Django. Introduction to Django databases I am hoping everyone knows what a database is, but ...


We may face issues when someone uses bots to abuse our system and send automated signup/password reset to random people. So hCaptcha is a really good way to avoid bots.
We will be using django-hCaptcha package from pypi.
pip install django-hCaptcha
# project/settings.py
INSTALLED_APPS = [
...
'hcaptcha',
]
# project/settings.py
...
HCAPTCHA_SITEKEY = '<your sitekey>'
HCAPTCHA_SECRET = '<your secret key>'
...
# app/forms.py
from allauth.account.forms import SignupForm, ResetPasswordForm
from hcaptcha.fields import hCaptchaField
class CustomSignupForm(SignupForm):
hcaptcha = hCaptchaField(theme='dark')
# if the order of fields isn't as you expected ,then you can use field_order
#field_order = ['username', 'email', 'password1', 'password2', 'hcaptcha']
#customize this according to your form
class CustomForgetPassword(ResetPasswordForm):
hcaptcha = hCaptchaField(theme='dark')
# project/settings.py
...
ACCOUNT_FORMS = {
'signup': '<app>.forms.MyCustomSignupForm',
'reset_password': '<app>.forms.CustomForgetPassword',}
...