完成个人中心—导航标签

    1. 个人中心—视图函数带标签页面参数tag
      @app.route('/usercenter/<user_id>/<tag>')
      def usercenter(user_id, tag):
         if tag == ‘1':
             return render_template('usercenter1.html', **context)

    2. 个人中心—导航标签链接增加tag参数
      <li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
    3. 个人中心—有链接到个人中心页面的url增加tag参数
      u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
 1 @app.route('/usercenter/<user_id>/<tag>')
 2 @loginFirst
 3 def usercenter(user_id,tag):
 4     user=User.query.filter(User.id==user_id).first()
 5     context={
 6         'user_id':user.id,
 7         'username': user.username,
 8         'fabus': user.fabu,
 9         'comments': user.comments
10     }
11     if tag=='1':
12         return render_template('usercenter1.html',**context)
13     elif tag=='2':
14         return render_template('usercenter2.html', **context)
15     else:
16         return render_template('usercenter3.html', **context)
 1 {% extends 'daohang.html' %}
 2 {% block title %}个人中心{% endblock %}
 3 {% block head %}
 4     <style>
 5         .nav_ul li{
 6             list-style:none;  {# 去掉点#}
 7             float: left;{# 左浮动#}
 8             margin:10px;{# 有边距,间隔开#}
 9         }
10     </style>
11 {% endblock %}
12 
13 {% block daohangbody %}
14 <ul class="nav_ul">{# <ul>标签定义无序列表,<li>标签定义无序列表单/项#}
15     <li role="presentation"><a href="{{ url_for('usercenter',user_id=user_id,tag=1) }}">information</a></li>
16      <li role="presentation"><a href="{{ url_for('usercenter',user_id=user_id,tag=2) }}">comments</a></li>
17      <li role="presentation"><a href="{{ url_for('usercenter',user_id=user_id,tag=3) }}">questions</a></li>
18 </ul>
19 {% block user %}{% endblock %}
20 {% endblock %}
 1 {% block daohangbody %}
 2     <div class="container">
 3         <div class="row clearfix">
 4 {#            <div class="col-md-2 column s1"></div>#}
 5             <div class="col-md-6 column">
 6                 <ul>
 7                     {% for foo in fabus %}
 8                         <li class="list-group-item">
 9                             <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
10                             <a href="{{ url_for('usercenter',user_id=foo.author_id,tag=1) }}">{{ foo.author.username }}</a>
11                             <br>
12                             <h4 class="text-center"><a href="{{ url_for('detail',question_id=foo.id) }}">{{ foo.title }}</a></h4>
13                             <span class="badge pull-right">{{ foo.creat_time }}</span>
14                             <p>{{ foo.detail }}</p>
15                         </li>
16                     {% endfor %}
17                 </ul>
18             </div>
19             <div class="col-md-6 column s1">
20 
21             </div>
22         </div>
23     </div>
24 {% endblock %}

 

posted on 2017-12-15 10:01  051刘佳铃  阅读(191)  评论(0)    收藏  举报