为窗体添加防机器人的验证机制
生活随笔
收集整理的這篇文章主要介紹了
为窗体添加防机器人的验证机制
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
安裝對應的模塊
pip install django-simple-captcha在setting,py中添加以下語句
INSTALLED_APPS = ('django.contrib.admin','django.contrib.auth','django.contrib.contenttypes','django.contrib.sessions','django.contrib.messages','django.contrib.staticfiles','oneapp01','captcha',#防偽機制包)在urls添加:
from django.conf.urls import include, url from django.contrib import adminurlpatterns = [url(r'^admin/', include(admin.site.urls)),url('^',include('oneapp01.urls')),url('^captcha/',include('captcha.urls')), ]確定是否裝了Pillow,用pip list, 沒有就pip install Pillow
以上步驟ok,就可以在窗口類forms.py或者model.py添加CaptchaField
from django.db import models from django import forms from captcha.fields import CaptchaField class PostForm(forms.ModelForm):captcha = CaptchaField()#防偽機制添加class Meta:model= Post#用于指定用哪個modelfields= ['mood','nickname','message','del_pass']#用于指定用model中哪些變量def __init__(self, *args, **kwarge):super(PostForm, self).__init__(*args, **kwarge)self.fields['mood'].label = '現在的心情'self.fields['nickname'].label = '你的昵稱'self.fields['message'].label = '你的消息'self.fields['del_pass'].label = '設置密碼'self.fields['captcha'].label = '確定你不是機器人' #防偽機制添加最后執行:
python manage.py makemigrations python manage.py migrate附上運行結果
轉載于:https://www.cnblogs.com/guguobao/p/9323711.html
總結
以上是生活随笔為你收集整理的为窗体添加防机器人的验证机制的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Cocoa之NSWindow常用总结
- 下一篇: Java多线程编程实战指南