1.个人中心—视图函数带标签页面参数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>',methods=['GET', 'POST']) @loginFirst def userCenter(user_id, tag): user = User.query.filter(User.id == user_id).first() context = { 'user':user, 'username': user.username, 'questions': user.question, 'comments': user.comment } if tag == '1': return render_template('userCenter1.html',**context) elif tag == '2': return render_template('userCenter2.html',**context) else: return render_template('userCenter3.html', **context)
2.个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
<li role="presentation" style="margin:1%; list-style: none;float: left;"><a href="{{ url_for ('userCenter',user_id=user.id,tag=1) }}">全部问答</a></li> <li role="presentation" style="margin:1%; list-style: none;float: left;"><a href="{{ url_for ('userCenter',user_id=user.id,tag=2) }}">全部评论</a></li> <li role="presentation" style="margin:1%; list-style: none;float: left;"><a href="{{ url_for ('userCenter',user_id=user.id,tag=3) }}">个人资料</a></li>
3.个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
<a class="author" href="{{ url_for ('userCenter',user_id=each.author.id,tag=1) }}">{{ each.author.username }}</a>