完成个人中心—导航标签
2017-12-19 11:16 055李小锐 阅读(180) 评论(0) 编辑 收藏 举报- 人中心—视图函数带标签页面参数tag
@app.route('/usercenter/<user_id>/<tag>')
def usercenter(user_id, tag):
if tag == ‘1':
return render_template('usercenter1.html', **context) - 个人中心—导航标签链接增加tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li> - 个人中心—有链接到个人中心页面的url增加tag参数
<a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a> - 主py文件
-
@app.route('/usercenter/<user_id>/<tag>') @login_re 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)
<lia role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag='1') }}">Questions</a> </lia> <lia role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag='2') }}">Comments</a> </lia> <lia role="presentation"><a href="{{ url_for('usercenter',user_id=user.id,tag='3') }}">Info</a> </lia>
base.html链接
<a href="{{ url_for('usercenter',user_id=session.get('userid'),tag=1)}}'">{{ session.get('user') }}
-
index.html链接
<a href="{{ url_for('usercenter',user_id=foo.author_id,tag=1) }}">{{ foo.author.username }}评论:({{ foo.comments|length }})</a>
detail.html链接
<a href="{{ url_for('usercenter',user_id=foo.author.id,tag=1) }}">{{ foo.author.username }}</a>