码迷,mamicode.com
首页 > 其他好文 > 详细

完成个人中心—导航标签

时间:2017-12-15 23:34:13      阅读:192      评论:0      收藏:0      [点我收藏+]

标签:log   ini   视图   temp   session   warning   get   group   col   

 

    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)
...
个人信息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">昵称:nini</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 %}

 

个人中心父模板
...
<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>
...

 

发布信息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
{% 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 %}


 

完成个人中心—导航标签

标签:log   ini   视图   temp   session   warning   get   group   col   

原文地址:http://www.cnblogs.com/nigongbin/p/8045032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!