赞
踩
官方文档:http://django-simple-captcha.readthedocs.io/en/latest/usage.html#installation
github:https://github.com/mbi/django-simple-captcha
版本:django 1.9
1
|
pip install django-simple-captcha==0.4.6
|
1
2
3
4
5
6
7
8
9
|
INSTALLED_APPS = [
'django.contrib.admin' ,
'django.contrib.auth' ,
'django.contrib.contenttypes' ,
'django.contrib.sessions' ,
'django.contrib.messages' ,
'django.contrib.staticfiles' ,
'captcha' ,
]
|
加入url(r'^captcha/', include('captcha.urls')),
1
2
3
4
5
6
7
|
from django.conf.urls import url, include
from django.contrib import admin
urlpatterns = [
url(r '^admin/' , admin.site.urls),
url(r '^captcha/' , include( 'captcha.urls' )),
]
|
1
2
|
makemigrations
migrate
|
app下自定义froms.py文件,创建一个注册form
1
2
3
4
5
6
7
|
from django import forms
from captcha.fields import CaptchaField
class RegisterForm(forms.Form):
email = forms.EmailField(required=True)
password = forms.CharField(required=True, min_length=5)
captcha = CaptchaField(error_messages={ "invalid" : u "验证码错误" })
|
1
2
3
4
5
6
7
|
from django.views.generic.base import View
class RegisterView(View):
def get(self, request):
register_form = RegisterForm()
return render(request, "register.html" , { "register_form" : register_form})
|
1
|
{{ register_form.captcha }}
|
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。