完成个人中心—导航标签

 

    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>

 

py文件:

...
# 跳转用户详情
@app.route('/yonghu/<username_id>/<tag>')   # 为了把页面分开,我们在html页面传了一个tag参数
def yonghu(username_id,tag):
    user = User.query.filter(User.id == username_id).first()
    context = {
        'userid': user.id,
        'username':user.username,
        'fabus':user.fabu,
        'comments':user.comments
    }   # 根据tag的不同去到不同页面,一个请求跳转3个不同页面
    if tag == '1':
        return render_template('yonghu1.html',**context)
    elif tag == '2':
        return render_template('yonghu2.html', **context)
    else:
        return render_template('yonghu3.html', **context)
...
py主文件

yonghufather.html:

...
<ul class="nav nav-pills">
            <li class="active" role="presentation"><a href="{{ url_for('yonghu',username_id=userid,tag=1) }}">个人信息</a></li>
            <li class="active" role="presentation"><a href="{{ url_for('yonghu',username_id=userid,tag=2) }}">发布信息</a></li>
            <li class="active" role="presentation"><a href="{{ url_for('yonghu',username_id=userid,tag=3) }}">评论信息</a></li>
        </ul>
...
个人中心父模板

yonghu1.html:

{% extends 'yonghufather.html' %}

{% block yonghubody %}
    <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">问答:{{ fabus|length }}篇</li>
        <li class="list-group-item-info">评论:{{ comments|length }}条</li>
    </ul>

{% endblock %}
个人信息html

yonghu2.html:

{% extends 'yonghufather.html' %}

{% block yonghubody %}

    <div>
        <h3 class="text-center">全部发布信息({{ fabus|length }})</h3>
        <ul class="list-unstyled">
            {% for foo in fabus %}
                <li class="list-group-item">
                    <a href="{{ url_for('yonghu',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('fabuview',fabu_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 %}
发布信息html

yonghu3.html:

{% extends 'yonghufather.html' %}

{% block yonghubody %}

    <div>
        <h3 class="text-center">全部评论信息({{ comments|length }})</h3>
        <ul class="list-unstyled">
            {% for foo in comments %}
                <li class="list-group-item">
                    <a href="{{ url_for('yonghu',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 %}
评论信息html

 

posted on 2017-12-15 09:31  L文斌  阅读(157)  评论(0编辑  收藏  举报