完成个人中心—导航标签

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

个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>

个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>

py:

...
@app.route('/own/<user_id>/<tag>')
@loginFirst
def own(user_id,tag):
    user=User.query.filter(User.id==user_id).first()
    context={
          'userid':user_id,
        'username':user.username,
        'question':user.question,
        'comments':user.comments
    }
    if tag=='1':
        return render_template('owncenter1.html',**context)
    elif tag == '2':
        return render_template('owncenter2.html', **context)
    else:
        return render_template('owncenter3.html', **context)
...

own.html:

{% extends "base.html" %}
{% block title %}个人中心{% endblock %}
{% block head %}
<style>
  .nav1 li{
        padding: 10px;
    }
</style>
{% endblock %}

{% block main %}

{% block own %}
      <div class="col-md-2 column "></div>
    <div class="col-md-8 column ">
<h3><span class="glyphicon glyphicon-user" aria-hidden="true"></span>{{user.username}}</h3>

    <ul class="nav nav-tabs">
        <li role="presentation"><a href="#">全部发布信息</a></li>
        <li role="presentation"><a href="#">全部评论信息</a></li>
        <li role="presentation"><a href="#">个人信息</a></li>
    </ul>
 </div>
    <div class="col-md-2 column "></div>
{% endblock %}

{% endblock %}

owncenter1:

{% extends 'own.html' %}

{% block own %}
    <div>
        <h3 class="text-center">全部发布信息({{ question|length }})</h3>
        <ul class="list-unstyled">
            {% for foo in question %}
                <li class="list-group-item">
                    <a href="{{ url_for('own',username_id=foo.author_id,tag=1) }}"><span
                            class="glyphicon glyphicon-fire"></span>{{ foo.author.username }}</a>
                    <h4 class="text-center"><a href="{{ url_for('comment',qcomment_id=foo.id) }}">{{ foo.title }}</a>
                    </h4>
                    <span class="badge pull-right">{{ foo.creat_time }}</span>
                    <br>
                    <p>{{ foo.detail }}</p>
                </li>
            {% endfor %}
        </ul>
        <br>
        <br>
        <br>
    </div>
{% endblock %}

 

owncenter2:

{% extends 'own.html' %}

{% block own %}
     <div>
        <h3 class="text-center">全部评论信息({{ comment|length }})</h3>
        <ul class="list-unstyled">
            {% for foo in comment %}
                <li class="list-group-item">
                    <a href="{{ url_for('own',username_id=foo.author_id,tag=1) }}"><span
                            class="glyphicon glyphicon-fire"></span>{{ foo.author.username }}</a>
                    <span class="badge pull-right">{{ foo.creat_time }}</span>
                    <p>{{ foo.detail }}</p>
                    <br>
                </li>
            {% endfor %}
        </ul>
        <br>
        <br>
        <br>
    </div>
{% endblock %}

 

owncenter3:

{% extends 'own.html' %}

{% block own %}
  <h3 class="text-center">个人信息</h3>
    <ul class="list-unstyled nav1">
        <li class="list-group-item-success">用户:{{ username }}</li>
        <li class="list-group-item-info">编号:{{ userid }}</li>
        <li class="list-group-item-warning">昵称:雪儿</li>
        <li class="list-group-item-danger">头像:</li>
        <li class="list-group-item-success">问答:{{ question|length }}篇</li>
        <li class="list-group-item-info">评论:{{ commentdetail|length }}条</li>
    </ul>
{% endfor %}

 

posted on 2017-12-15 16:14  152陈斯璐  阅读(157)  评论(0编辑  收藏  举报