lis = []#設(shè)置一個(gè)空列表用來存放發(fā)送的驗(yàn)證碼,用來驗(yàn)證
def yzm1():
res1 = ""
for i in range(4):#用四個(gè)隨機(jī)數(shù)組成驗(yàn)證碼
num = random.randint(0, 9)
res1 += str(num)
lis.append(res1)#將驗(yàn)證碼放入空的列表中
return res1#返回驗(yàn)證碼
class zc(View):
def get(self, request):
return render(request, 'zc.html', locals())
def post(self, request):
name = request.POST['qq']#獲取前端傳遞進(jìn)來的數(shù)據(jù)
subject = '驗(yàn)證碼'
message = vercode()#獲取驗(yàn)證碼
form = '837620306@qq.com'#獲取發(fā)送驗(yàn)證碼的郵箱
# EMAIL_HOST_USER
rcipient_list = [name]
res = send_mail(subject=subject, message=message, from_email=form, recipient_list=rcipient_list)#發(fā)送驗(yàn)證碼返貨真或假,假代表沒有發(fā)送成功
if res == 1:#判斷是否發(fā)送成功
return redirect('/app01/yzm/')#成功的話跳轉(zhuǎn)到驗(yàn)證的網(wǎng)頁
else:#不成功的話返回注冊(cè)界面
return render(request, 'zc.html', locals())
def yzm2(request):
if request.method == 'GET':
return render(request, 'yzm.html', locals())
elif request.method == 'POST':
a = request.POST['much']#獲取到用戶輸入的驗(yàn)證碼
if a == lis[-1]:#取最新的驗(yàn)證碼
return HttpResponse('驗(yàn)證碼正確')
else:
return HttpResponse('no')
用來發(fā)送驗(yàn)證碼的郵箱需要打開POP3/SMTP服務(wù)和IMAP/SMTP服務(wù),并且獲得POP3/SMTP服務(wù)的授權(quán)碼
到此這篇關(guān)于django注冊(cè)用郵箱發(fā)送驗(yàn)證碼的實(shí)現(xiàn)的文章就介紹到這了,更多相關(guān)django 郵箱驗(yàn)證碼內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!