Django captcha 验证

1.安装模块

复制代码
pip install django-simple-captcha
pip install Pillow

2.在settings中,将captcha注册到app列表里

复制代码
# MxOnline/settings.py
INSTALLED_APPS = [
    # 图片登陆验证
    'captcha',
]

3.captcha需要在数据库中建立自己的数据表,所以需要执行migrate命令生成数据表:

复制代码
py manage.py migrate

4.添加url路由

根目录下的urls.py文件中增加captcha对应的网址:

复制代码
# MxOnline/urls.py
urlpatterns = [
    path('register', RegisterView.as_view(), name='register'),
    # 这是生成验证码的图片
    path('captcha/',include('captcha.urls')),
]

5.修改forms

复制代码
# users/forms.py
from captcha.fields import CaptchaField



class RegisterForm(EmailCheckMixin):
    """注册表单"""
 
    # 为生成的验证码图片,以及输入框
    captcha = CaptchaField(error_messages={'invalid': '验证码错误'})
相关推荐
wj3055853788 小时前
课程 9:模型测试记录与 Prompt 策略
linux·人工智能·python·comfyui
星寂樱易李9 小时前
iperf3 + Python-- 网络带宽、网速、网络稳定性
开发语言·网络·python
qingfeng154159 小时前
企业微信机器人开发:如何实现自动化与智能运营?
人工智能·python·机器人·自动化·企业微信
彦为君12 小时前
Agent 安全:从权限提示到沙箱隔离
python·ai·ai编程
PILIPALAPENG13 小时前
Python 语法速成指南:前端开发者视角(JS 类比版)
前端·人工智能·python
用户83562907805114 小时前
Python 操作 PowerPoint 页眉与页脚指南
后端·python
枫叶林FYL14 小时前
项目九:异步高性能爬虫与数据采集中枢 —— 基于 Crawl<sub>4</sub>AI 与 Playwright 的现代化数据采集平台 项目总览
爬虫·python·深度学习·wpf
猫猫的小茶馆15 小时前
【Python】函数与模块化编程
linux·开发语言·arm开发·驱动开发·python·stm32
Miss_min15 小时前
128K长序列数据生成
开发语言·python·深度学习