config.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("usercenter1.html",**context)
elif tag =="2":
return render_template("usercenter2.html",**context)
else:
return render_template("usercenter3.html", **context)
if __name__ == '__main__':
app.run(debug=True)
usercenter.html
{% extends 'base.html' %}
{% block title %}个人中心{% endblock %}
{% block main %}
<h3><span class="glyphicon glyphion-user" aria-hidden="true"><span/>{{user.username}}<h3>
<ul class="nav nav-tabs">
<li role="presentation" class="active"><a href='{{url_for('usercenter',user_id = user.id,tag = 1) }}'>全部问答</li></li>
<li role="presentation" class="active"><a href='{{url_for('usercenter',user_id = user.id,tag = 2) }}'>全部评论</li></li>
<li role="presentation" class="active"><a href='{{url_for('usercenter',user_id = user.id,tag = 3) }}'>个人资料</li></li>
</ul>
{% block user %} {% endblock %}
{% endblock %}
base.html
<a href="{{url_for('usercenter',user_id = session.get('userid'), tag=1)}}">{{session.get('user') }}</a>
detail.html
<a href="{{url_for('usercenter',user_id = ques.author_id,tag=1)}}">{{foo.author.username }}</a>
index.html
<a href="{{url_for('usercenter',user_id = foo.author_id,tag=1)}}">{{foo.author.username }}</a>