我的中心—視圖函數帶標籤頁面參數tag
@app.route('/usercenter/<user_id>/<tag>')
def usercenter(user_id, tag):
if tag == ‘1':
return render_template('usercenter1.html', **context)html
py:session
@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) if tag == ‘2': return render_template('usercenter2.html', **context) if tag == ‘3': return render_template('usercenter3.html', **context)
2.我的中心—導航標籤連接增長tag參數
<li role=「presentation」><a href=「{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">所有問答</a></li>app
username,html函數
{% extends 'base.html' %} {% block title %}我的中心{% endblock %} {% block head %} <style> .nav_ul li { list-style: none; float: left; margin: 30px; } </style> {% endblock %} {% block main %} <h3><span class="glyphicon glyhicon-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’) }}">所有問答</a></li>所有問答</a></li> <li role=「presentation」><a href=「{{ url_for(‘usercenter’,user_id = user.id,tag = ‘2’) }}">所有評論</a></li> <li role=「presentation」><a href=「{{ url_for(‘usercenter’,user_id = user.id,tag = ‘3’) }}">我的資料</a></li> </ul> {% block user %}{% endblock %} {% endblock %}
3.url
我的中心—有連接到我的中心頁面的url增長tag參數
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>spa
base.htmlcode
u <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
index,htmlhtm
u <a href="{{ url_for('usercenter',user_id = foo.author_id, tag=1) }}">{{ foo.author.username }}</a>
detail.htmlblog
<a href="{{ url_for('usercenter',user_id =ques.author_id, tag=10)}}foo.author.username }}">{{
foo.author.username
}}</a>