利用django-simple-captcha生成验证码
2024-10-19 20:30:57
参考文档
http://django-simple-captcha.readthedocs.io/en/latest/
django支持1.7+
1.安装
pip install django-simple-captcha
2.添加到install_apps中
略
3.添加以下url到urls文件中
from django.conf.urls import url,include
url(r'^captcha/', include('captcha.urls')), #添加到url
4.生成数据库
makemigrations
migrate
5.应用配置
- 在forms.py中导入以下模块
from captcha.fields import CaptchaField
在下关Forms中使用
class RegisterForm(forms.Form):
email = forms.EmailField(required=True)
password = forms.CharField(required=True,min_length=5)
captcha = CaptchaField(error_messages={'invalid':u'验证码错误'})
- 在views.py中使用forms
class RegisterView(View):
def get(self,request):
register_form = RegisterForm()
return render(request,'register.html',{'register_form':register_form})
def post(self,request):
register_form = RegisterForm()
if register_form.is_valid():
user_name = request.POST.get("username", '')
pass_word = request.POST.get("password", '')
user_profile = UserProfile()
user_profile.username = user_name
user_profile.email = user_name
user_profile.password = make_password(pass_word)
user_profile.save()
6.前端渲染即可
最新文章
- 加快http请求图片的速度
- 关于Vector中的元素中含有指针成员的情况
- IP包格式
- UITableView &; UITableViewController
- Python爬取17吉他网吉他谱
- 如何在Blog中使用feedburner管理RSS订阅
- 344. Reverse String(C++)
- Turn the corner (三分)
- Sublime text3 设置的中文翻译
- 《Thinking in Java》学习笔记(五)
- easyui validatebox textbox 取值和赋值
- MySQL:参数wait_timeout和interactive_timeout以及空闲超时的实现【转】
- js array 对象
- 第六章 使用 Bootstrap Typeahead 组件(百度下拉效果)(续)
- 泡泡一分钟:Exploiting Points and Lines in Regression Forests for RGB-D Camera Relocalization
- 学JS的心路历程-Promise(一)
- cocos2d-x 旅程開始--(实现单击与长按)
- java学习笔记—第三方数据库连接池包1(29)
- 【DFS】Anniversary Cake
- 【bzoj3329】Xorequ 矩阵快速幂
热门文章
- 2018.11.02 洛谷P2661 信息传递(拓扑排序+搜索)
- RecyclerView怎么能没有ItemClickListener?加一个!
- C#-VS支持的语言
- Forward团队-爬虫豆瓣top250项目-设计文档
- java理论学时第七节。课后作业。
- Java理论学时第二节。课后作业。
- C#期末大作业 消消乐 2017-06-01 18:11 275人阅读 评论(0) 收藏
- Bloom Filter 算法简介 (增加 Counting Bloom Filter 内容)
- jvm调优的分类
- cocos游戏网址