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

完成个人中心—导航标签

时间:2017-12-15 20:08:54      阅读:123      评论:0      收藏:0      [点我收藏+]

标签:foo   ext   active   div   styles   blog   enter   type   gpo   

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

@app.route(‘/usercenter/<user_id>/<tag>‘)
@loginFirst
def usercenter(user_id, tag):
    user = User.query.filter(User.id == user_id).first()
    context = {
        ‘username‘: user.username,
        ‘sent‘: user.sent,
        ‘comments‘: user.comments,
        ‘user‘: user
    }
    if tag == ‘wenda‘:
        return render_template(‘wenda.html‘, **context)
    elif tag == ‘pinlun‘:
        return render_template(‘pinlun.html‘, **context)
    else:
        return render_template(‘GRZX.html‘, **context)
    1. 个人中心—导航标签链接增加tag参数
      <li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
<!DOCTYPE html>
<html lang="en">
<head>
    {% extends ‘index.html‘ %}
    <meta charset="UTF-8">
    <title>{% block title %}
        个人
    {% endblock %}</title>
    {% block head %}
        <link rel="stylesheet" type="text/css" href="{{ url_for(‘static‘,filename=‘css/user.css‘) }}">
    {% endblock %}
</head>
<body>
{% block body %}
    <div class="all">

        <ul class="nav_ul">
            <li role="presentation" class="active"><a
                    href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘wenda‘) }}">问答</a></li>
            <li role="presentation"><a
                    href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘pinlun‘) }}">评论</a></li>
            <li role="presentation"><a href="{{ url_for(‘usercenter‘ ,user_id=user.id,tag=‘geren‘) }}">个人信息</a></li>
        </ul>
    </div>
    {% block user %}{% endblock %}
{% endblock %}

</body>
</html>

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

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

#首页
 <a class="nickname"
                                   href="{{ url_for(‘usercenter‘,user_id=foo.author_id,tag=‘wenda‘)}}">{{ foo.author.username }}</a>
#详情页:
<a href="{{ url_for(‘usercenter‘,user_id=foo.author.id,tag=‘wenda‘) }}">{{ foo.author.username }}</a>
#导航
  <li><a href="{{ url_for(‘usercenter‘,user_id=user.id,tag=‘wenda‘) }}">{{ usern }}</a></li>

 

完成个人中心—导航标签

标签:foo   ext   active   div   styles   blog   enter   type   gpo   

原文地址:http://www.cnblogs.com/pys965085265/p/8044588.html

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