一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

Django使用django-simple-captcha做验证码实现代码示例

时间:2021-01-07 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下Django使用django-simple-captcha做验证码实现代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

安装django-simple-captcha

pip install django-simple-captcha

将captcha 安装在installed_apps里面

将captcha配置url

迁移同步,生成captcha所依赖的表

python manage.py makemigrations
python manage.py migrate

将captcha字段在form类当中进行设置, 但是要导入from captcha.fields import CaptchaField

在后台逻辑当中,get请求里面实例化我们的form,将form对象返回到页面

在页面上通过{{ form.captcha}} 获取验证码

效果图

注册成功

热门栏目