完成个人中心—导航标签
个人中心—视图函数带标签页面参数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, 'questions':user.questions, 'comments':user.comments } if tag =='question': return render_template('user question.html',**context) elif tag =='comment': return render_template('user comment.html', **context) else: return render_template('user information.html', **context)
个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>
<ul class="nav nav-tabs"> <li><a href="{{ url_for('usercenter',user_id = user.id,tag ='information') }}">个人资料</a></li> <li><a href="{{ url_for('usercenter',user_id = user.id,tag ='comment') }}">全部评论</a></li> <li><a href="{{ url_for('usercenter',user_id = user.id,tag ='question') }}">全部问题</a></li> </ul>
个人中心—有链接到个人中心页面的url增加tag参数
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
<a href="{{ url_for('usercenter',user_id=session.get('user.id'),tag='information') }}">{{ username }}</a> <a href="{{ url_for('usercenter',user_id=ques.author_id,tag='information') }}">{{ foo.author.username }}</a>