前端部分(主要是if进行一个判断)
判断是否登录,登录了展示不同内容!
<ul class="nav navbar-nav navbar-right">
{% if request.user.is_authenticated %}
<li><a href="#">{{ request.user.username }}</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-haspopup="true" aria-expanded="false">更多操作 <span class="caret"></span></a>
<ul class="dropdown-menu">
<li><a href="#">修改头像</a></li>
<li><a href="" data-toggle="modal" data-target=".bs-example-modal-lg">修改密码</a></li>
<li><a href="#">后台管理</a></li>
<li role="separator" class="divider"></li>
<li><a href="{% url 'logout' %}">退出登录</a></li>
</ul>
<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>
</li>
{% else %}
<li><a href="{% url 'login' %}">登录</a></li>
<li><a href="{% url 'reg' %}">注册</a></li>
{% endif %}
</ul>
后端部分
def home(request):
#将request传到前端页面,用于判断是否登录
return render(request,'home.html',locals())
标签:新密码,登录,request,修改,首页,home,bbs,搭建
From: https://www.cnblogs.com/suncolor/p/16758527.html