个人中心—视图函数带标签页面参数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 = { 'user': user } if tag =='1': return render_template('user1.html',**context) elif tag =='2': return render_template('user2.html', **context) else: return render_template('user3.html', **context)
个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
<ul class="nav_ul"> <li role="presentation>"><a href="{{ url_for(usercenter,user_id=user.id,tag='1') }}">个人资料</a> </li> <li role="presentation>"><a href="{{ url_for(usercenter,user_id=user.id,tag='2') }}">全部问答</a> </li> <li role="presentation>"><a href="{{ url_for(usercenter,user_id=user.id,tag='3') }}">全部评论</a> </li> </ul>
个人中心—有链接到个人中心页面的url增加tag参数
<a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
<ul class="list-group"> {% for foo in questions %} <li class="list-group-item"> <span class="glyphicon" glyphicon-leaf aria-hidden="true"></span> <a href="{{ url_for('usercenter',user_id = foo.author.id,tag = '1') }}">用户名:{{ foo.author.username }}</a> <br> <a href="{{ url_for('xiangqing',question_id = foo.id) }}">标题:{{ foo.title }}</a> <span class="badge">{{ foo.creat_time }}</span> <br> <p class="neirong">内容:{{ foo.detail }}</p> </li> {% endfor %} </ul>