主要利用的是bootstrap3中js插件里的模態(tài)框版塊
新羅網(wǎng)站制作公司哪家好,找成都創(chuàng)新互聯(lián)公司!從網(wǎng)頁設計、網(wǎng)站建設、微信開發(fā)、APP開發(fā)、自適應網(wǎng)站建設等網(wǎng)站項目制作,到程序開發(fā),運營維護。成都創(chuàng)新互聯(lián)公司自2013年起到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設就選成都創(chuàng)新互聯(lián)公司。
<li><a href="" data-toggle="modal" data-target=".bs-example-modal-lg">修改密碼</a></li>
<div class="modal fade bs-example-modal-lg" tabindex="-1" role="dialog" aria-labelledby="myLargeModalLabel">
<div class="modal-dialog modal-lg" role="document">
<div class="modal-content">
<div class="row">
<div class="col-md-8 col-md-offset-2">
<h3 class="text-center">修改密碼</h3>
<div class="form-group">
<label for="">用戶名:</label>
<input type="text" disabled value="{{ request.user.username }}" class="form-control" id="id_username">
</div>
<div class="form-group">
<label for="">原密碼:</label>
<input type="text" id="old_password" class="form-control">
</div>
<div class="form-group">
<label for="">新密碼:</label>
<input type="password" id="id_password" class="form-control">
</div>
<div class="form-group">
<label for="">新密碼:</label>
<input type="text" id="confirm_password" class="form-control">
</div>
<span style="color:red;" id="error"></span>
<div class="modal-footer">
<button type="button" class="btn btn-primary" data-dismiss="modal" >取消</button>
<button type="button" class="btn btn-primary" id="commit">修改</button>
</div>
</div>
</div>
<br>
</div>
</div>
</div>
<script>
$('#commit').click(function (){
$.ajax({
type:'post',
url:'/set_password/',
data:{
'username':$('#id_username').val(),
'old_password':$('#old_password').val(),
'password':$('#id_password').val(),
'confirm_password':$('#confirm_password').val(),
'csrfmiddlewaretoken':'{{ csrf_token }}',
},
success:function (args){
if (args.code==1000){
window.location.reload();
}else {
$('#error').text(args.msg)
}
}
})
})
</script>
注意修改密碼的視圖函數(shù)必須是登錄用戶才能使用,所以需要一個@login_required裝飾器
@login_required
def set_password(request):
# 1.判斷是否為ajax請求
if request.method == 'POST':
back_dic = {'code':1000,'msg':''}
# 2.獲取用戶修改密碼提交的數(shù)據(jù)
username = request.POST.get('username')
old_password = request.POST.get('old_password')
password = request.POST.get('password')
confirm_password = request.POST.get('confirm_password')
# 3.對比原密碼是否正確
is_right = request.user.check_password(old_password)
if is_right:
# 4.判斷兩次密碼是否一致
if password == confirm_password:
# 5.一致則修改密碼
request.user.set_password(password)
request.user.save()
else:
back_dic['code'] = 1001
back_dic['msg'] = '兩次密碼不一致'
else:
back_dic['code'] = 1002
back_dic['msg'] = '原密碼不正確'
return JsonResponse(back_dic)
網(wǎng)頁名稱:修改密碼彈出框搭建
URL分享:http://m.kartarina.com/article34/dsogcpe.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供服務器托管、外貿(mào)網(wǎng)站建設、、微信小程序、商城網(wǎng)站、小程序開發(fā)
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)