个人中心标签页导航
新页面userbase.html,用<ul ><li role="presentation"> 实现标签页导航。
<ul class="nav nav-tabs">
<li role="presentation"><a href="#">Home</a></li>
<li role="presentation"><a href="#">Profile</a></li>
<li role="presentation"><a href="#">Messages</a></li>
</ul>
<ul class="nav_ul"> <li role="presentation"><a href="#">全部问答</a></li> <li role="presentation"><a href="#">全部评论</a></li> <li role="presentation"><a href="#">个人信息</a></li> </ul>
让userbase.html继承base.html。
重写title,head,main块.
将上述<ul>的样式放在head块,<ul>放在main块中.
定义新的块user。
{% extends 'base.html' %} {% block title %} 个人中心 {% endblock %} {% block head %} <style> .out{ position: absolute; left:22%; top: 13%; } .nav_ul li{ list-style: none; float: left; margin: 10px; text-decoration: none; font-size: 20px; } .content{ text-align: center; width: 800px; height: 100px; padding: 10px; border:1px solid burlywood; } #qu2{ width: 30px; height: 30px; } </style> {% endblock %} {% block main %} <div class="out"> <div class="content"> <span class="glyphicon-leaf" aria-hidden="true"></span><img id="qu2" src="{{ url_for('static',filename='images/question.jpg')}}"> <span style="font-size: 30px ">{{ username }}</span> <ul class="nav_ul"> <li role="presentation"><a href="#">全部问答</a></li> <li role="presentation"><a href="#">全部评论</a></li> <li role="presentation"><a href="#">个人信息</a></li> </ul> </div> </div> {% block user %} {% endblock %} {% endblock %}
让上次作业完成的个人中心页面,继承userbase.html,原个人中心就自动有了标签页导航。
制作个人中心的三个子页面,重写user.html中定义的user块。
思考 如何实现点标签页导航到达不同的个人中心子页面。
{% extends "userbase.html" %} {% block user %} <div class="big"> <div class="content"> <span class="glyphicon-leaf" aria-hidden="true"></span><img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"> {{ user.username }}<br><small>全部问答:</small></h3> <ul class="list-group"> {% for foo in user.question %} <li class="list-group-item"> <span class="glyphicon-leaf" aria-hidden="true"></span> <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"> <a href = "">{{ foo.author.username }}</a> <span class="badge">评论时间:{{ foo.create_time }}</span> <p style="text-align: left">{{ foo.detail }}</p> </li> {% endfor %} </ul> </div> </div> {% endblock %}
{% extends 'userbase.html' %} {% block user %} <div class="big"> <div class="content"> <h3><span class="glyphicon-leaf" aria-hidden="true"></span> <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"> {{ user.username }}<br><small>全部评论:</small></h3> <ul class="list-group"> {% for foo in user.comments %} <li class="list-group-item"> <span class="glyphicon-leaf" aria-hidden="true"></span> <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"><a href = "">{{ foo.author.username }}</a> <span class="badge">评论时间:{{ foo.create_time }}</span> <p style="text-align: left">{{ foo.detail }}</p> </li> {% endfor %} </ul> </div> </div> {% endblock %}
{% extends 'userbase.html' %} {% block user %} <div class="big"> <div class="content"> <h3><span class="glyphicon-leaf" aria-hidden="true"></span> <img id="qu" src="{{ url_for('static',filename='images/question.jpg')}}"> {{ user.username }}<br> <small>个人信息:</small></h3> <ul class="list-group"> <li class="list-group-item">用户:{{ user.username }}</li> <li class="list-group-item">编号:{{ user.id }}</li> <li class="list-group-item">昵称:{{ user.nickname }}</li> <li class="list-group-item">文章篇数:{{ user.question|length }}</li> </ul> </div> </div> {% endblock %}