1 @app.route(‘/usercenter/<user_id>/<tag>‘) 2 @loginFirst 3 def usercenter(user_id,tag): 4 user = User.query.filter(User.id==user_id).first 5 context ={ 6 ‘user‘:user 7 } 8 if tag ==‘1‘: 9 return render_template(‘usercenter1.html‘, **context) 10 elif tag ==‘2‘: 11 return render_template(‘usercenter2.html‘, **context) 12 else: 13 return render_template(‘usercenter3.html‘, **context) 14 复制代码
1 <ul class="nav_ul"> 2 <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id= user.id,tag=1) }}">全部提问</a></li> 3 <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id= user.id,tag=2) }}">全部评论</a></li> 4 <li role="presentation"><a href="{{ url_for(‘usercenter‘,user_id= user.id,tag=3) }}">个人信息</a></li> 5 </ul> 6 7 <a href="{{ url_for(‘usercenter‘,user_id=foo.author_id,tag=1)}}">{{ foo.author.username}}</a> 8 <a href="{{ url_for(‘usercenter‘,user_id= session.get(‘id‘),tag =1) }}">{{ session.get(‘user‘) }}</a>