实现逻辑: {% if request.user.is_authenticated %} 个人信息{% else %}登录{% endif %}
直接上代码
{% if request.user.is_authenticated %} <div class="personal"> <dl class="user fr"> <dd>{{ request.user.username }}<img class="down fr" src="/static/images/top_down.png"/></dd> <dt><img width="20" height="20" src="{{ MEDIA_URL }}{{ request.user.image }}"/></dt> </dl> <div class="userdetail"> <dl> <dt><img width="80" height="80" src="{{ MEDIA_URL }}{{ request.user.image }}"/></dt> <dd> <h2>{{ request.user.nick_name }}</h2> <p>{{ request.user.username }}</p> </dd> </dl> <div class="btn"> <a class="personcenter fl" href="{% url "users:user_info" %}">进入个人中心</a> <a class="fr" href="/logout/">退出</a> </div> </div> </div> <a href="usercenter-message.html"> <div class="msg-num"><span id="MsgNum">0</span></div> </a> {% else %} <a style="color:white" class="fr registerbtn" href="register.html">注册</a> <a style="color:white" class="fr loginbtn" href="login.html">登录</a> {% endif %}