Blog Project Source: Https://github.com/JmilkFan/JmilkFan-s-Blog Directory
Table of Contents list reCAPTCHA application reCAPTCHA
List of the preceding text
Use flask to write a light blog (1)-Create a project
Write a light blog with flask (2)-hello world.
Write a light blog with flask (3)-(m) vc_ connect MySQL and SQLAlchemy
Write a light blog with flask (4)-(m) vc_ create data models and tables
Write a light blog with flask (5)-( M) Vc_sqlalchemy CRUD detailed
Use flask to write a light blog (6)-(m) vc_models relationship (one to many)
use flask to write a light blog (7)-(m) vc_models Relationship (many to many)
Write a light blog with flask (8)-(M) vc_alembic Manage database structure upgrades and downgrades
Use flask to write a light blog (9)-M (V) C_jinja Syntax Basics Quick Overview
Write a light blog with flask-M (v) C_jinja common filters and flask special variables and methods
Use flask to write a light blog (one)-M (v) c_ CREATE view function
Write a light blog with flask (12)- M (v) C_ writes and inherits Jinja templates
Write a light blog with flask-M (v) C_wtforms service-side form validation
Write a light blog (v)-M (v.) the template of the C_ Implementation Project's homepage
with F Lask to write a light blog.-M (V) C_ Implementation Blog page comment form
Use flask to write a light blog (c) _flask Blueprint Blueprint
to write a light blog (flask)-MV (c) _ should Refactoring projects with blueprints
Use flask to write a light blog (18)-use Factory mode to generate application objects
flask to write a light blog (19)-Bcrypt ciphertext store account information and implement user login form recaptcha< /strong>
CMU designed a powerful system called reCAPTCHA to let their computers go to humans for help. The specific approach is: OCR software can not recognize the text scan map to the world's major sites to replace the original code pictures, the users of these sites in the correct recognition of these words, the answer will be returned to CMU. So reCAPTCHA is essentially a distributed text recognition system (OCR) that is covered by a captcha.
reCAPTCHA is a technique that uses the CAPTCHA (fully automated distinction between computer and human Turing tests) to identify characters in old books that are difficult to be recognized by OCR, aided by the human brain's ability to discern characters that are difficult to recognize. In other words, recaptcha can not only spam (spam), but also help to digitize the ancient books (can be called artificial OCR). I can only say that the idea is absolutely absolute. So even because reCAPTCHA is Google's products in the domestic can not be used normally, but will still be applied to our Blog project, and then through the application of reverse proxy to make it feasible.
Use : reCAPTCHA is not complex to use, after registering a Google user name, into the reCAPTCHA official website and enter your blog name (fill in) and domain name (only support domain names and subdomains, now we temporarily use localhost, After deployment to the line will also need to fill in the new domain name, you will get a public Key, you can use it on your reCAPTCHA plug-in, while reCAPTCHA also support multiple sites.
As pictured above, reCAPTCHA will show you how to integrate it into the client and server. It is recommended that you back up this information, especially public Key and <script>.
Client-side Integration:
Paste This snippet before the closing tag on your HTML template:
<script src= ' https://www.google.com/recaptcha/api.js ' ></script>
Paste This snippet in the the Where you want the reCAPTCHA widget to appear:
<div class= "G-recaptcha" data-sitekey= "<your public key>" ></div>
Server-side Integration:
When your users submit the form where you integrated reCAPTCHA and you'll get as part of the payload a string with the name G-recaptcha-response ". In order to check whether Google has verified this user, send a POST request with these parameters:
Url:
Https://www.google.com/recaptcha/api/siteverify
Application reCAPTCHAconfig.py
Class Config (object): ""
Base Config class.
"" # Wtform secret key
Secret_key = ' wtforms key '
# reCAPTCHA public key and Private key
Recaptcha_public_key = ' <your public key> "
recaptcha_private_key =" <your PRIVATE key> "
forms.py
from flask_wtf import form, Recaptchafield class Registerform (Form): "" "" " Username = Stringfield (' username ', [datarequired (), Length (max=255)]) password = Passwordfield (' Password ', [datare Quired (), Length (min=8)]) comfirm = Passwordfield (' Confirm Password ', [DataRequired (), Equalto (' Password ')]) recap Tcha = Recaptchafield () def validate (self): check_validate = Super (Registerform, self). Validate () # If validator no pass if not Check_validate:return False # Check the user whether already exi
St. user = User.query.filter_by (username=self.username.data). A () if User:self.username.errors.append (
' User with ' name already exists. ') Return False to return True