Django Verification Code

Source: Internet
Author: User
Tags install django pip install django

Django Simple Captcha function

Dependency Packages

Libz-dev Libjpeg-dev Libfreetype6-dev Python-dev

One, download the package, copy the CAPTCHA to the project

Https://github.com/mbi/django-simple-captcha


Second, the operation

Pip Install Django-simple-captcha

Third, add to settings.py

Installed_apps = [' Captcha ',]

Four, the operation

Python manage.py Migrate

V. Modification of urls.py

From django.conf.urls import url,includeurlpatterns = [url (r ' ^captcha/', include (' Captcha.urls ')),]

Vi. Modification of form

form.py adding CAPTCHA

From captcha.fields import captchafieldclass loginform (forms. Form):     username = forms. Charfield (label= ' username ', widget=forms. TextInput (attrs={"placeholder":  "user name",  "required":  "required",}),                                 max_length=50, error_messages={"Required":  " Username cannot be empty ",})     password = forms. Charfield (label= ' password ', widget=forms. Passwordinput (attrs={"placeholder":  "password",  "required":  "required",}),                                 max_length=20, error_messages={"Required":  " Password cannot be empty ",})     captcha = captchafield (label= ' Verification code')     def clean (self):         #验证码          try:             captcha_x = self.cleaned_data[' Captcha ']         except exception as e:             print  (' except:  '  + str (e))              raise forms. ValidationError ("Wrong verification code, please re-enter")


This article is from the "Silver Fox" blog, please be sure to keep this source http://foxhound.blog.51cto.com/1167932/1828510

Django Verification Code

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.