• django框架管理员登录页面添加验证码功能


    B站视频-3分钟
    https://www.bilibili.com/video/BV1TW421P7YD/
    
    • 1
    • 2

    Django Simple Captcha 0.6.0 版本

    # 1官网
    [Django Simple Captcha — Django Simple Captcha 0.6.0 documentation (django-simple-captcha.readthedocs.io)](https://django-simple-captcha.readthedocs.io/en/latest/)
    # 2使用方法
    [Using django-simple-captcha — Django Simple Captcha 0.6.0 documentation](https://django-simple-captcha.readthedocs.io/en/latest/usage.html)
    # 3github项目地址
    [GitHub - mbi/django-simple-captcha:Django Simple Captcha 是一个非常简单但高度可定制的 Django 应用程序,可以将验证码图像添加到任何 Django 表单中。](https://github.com/mbi/django-simple-captcha)
    
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    1:安装命令

    pip install  django-simple-captcha
    
    • 1

    2:在django项目中的settings.py中的INSTALLED_APPS中添加安装插件

    INSTALLED_APPS=[
    
    'django内置插件开头'
    'django内置插件结尾'
    'captch'
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    3:安装完django-simple-captcha之后,才安装django-multi-captcha-admin 多合一版本

    django-multi-captcha-admin 多合一版本

    # 1不同展示方式
    [GitHub - a-roomana/django-multi-captcha-admin: easy add captcha to login page of django admin](https://github.com/a-roomana/django-multi-captcha-admin)
    # 2线上视频
    [向 Django 管理员添加验证码 - YouTube](https://www.youtube.com/watch?v=JYEwOSBcKvY&ab_channel=CloudWithDjango) 
    
    • 1
    • 2
    • 3
    • 4

    1:安装命令

    pip install  django-multi-captcha-admin
    
    • 1

    2:在django项目中的settings.py中的INSTALLED_APPS中添加安装插件

    INSTALLED_APPS=[
    'multi_captcha_admin',
    'django内置插件开头'
    'django内置插件结尾'
    'captcha',
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    3:执行django的迁移

    python manage.py migrate
    
    • 1

    4:在urls.py中添加captcha路由

    from django.urls import path, include  
      
    urlpatterns = [  
        path('admin/', admin.site.urls),  
        path('admin/login/', custom_login, name='custom_login'),  
        path('captcha/',include('captcha.urls')),  
    ]
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7

    5:在settings.py文件中添加 指定的验证码引擎

    MULTI_CAPTCHA_ADMIN={
    	'engine':'simple-captcha',
    }
    MIDDLEWARE=[]
    
    • 1
    • 2
    • 3
    • 4

    使用recaptcha2引擎

    MULTI_CAPTCHA_ADMIN={
    	'engine':'recaptcha2',
    }
    
    请参考以下说明
    [GitHub - kbytesys/django-recaptcha2: Django reCaptcha v2 field/widget](https://github.com/kbytesys/django-recaptcha2)
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6

    使用recaptcha引擎

    MULTI_CAPTCHA_ADMIN={
    	'engine':'recaptcha',
    }
    请参考以下说明
    [GitHub - django-recaptcha/django-recaptcha: Django reCAPTCHA form field/widget integration app.](https://github.com/django-recaptcha/django-recaptcha)
    
    • 1
    • 2
    • 3
    • 4
    • 5
  • 相关阅读:
    【浅尝C++】STL第三弹=>list常用接口使用示例/list底层结构探索/list模拟实现代码详解
    逻辑运算符
    产品经理工作流程
    【LeetCode刷题记录】92. 反转链表 II & 25. K 个一组翻转链表
    04-Redis源码数据结构之字典
    C语言——三种方式实现学生信息管理
    【矩阵论】2. 矩阵分解——高低分解
    Another app is currently holding the yum lock; waiting for it to exit
    算法的奇妙世界:从原理到应用的探索
    Android 实现禁止复制
  • 原文地址:https://blog.csdn.net/weixin_47021806/article/details/136345093