三十5、完成我的中心—导航标签

1.我的中心—视图函数带标签页面参数tag
@app.route('/usercenter/<user_id>/<tag>')
def usercenter(user_id, tag):
   if tag == ‘1':
       return render_template('usercenter1.html', **context)html

@app.route('/usercenter/<user_id>/<tag>')
@loginFirst
def usercenter(user_id, tag):
    user = User.query.filter(User.id == user_id).first()
    context = {
        'user':user,
        # 'username':user.username,
        'question' : user.question,
        'comments': user.comments
    }
    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)

 

2.我的中心—导航标签连接增长tag参数
<li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">所有问答</a></li>session

{% extends "base.html" %}
{% block title %}我的中心-{% endblock %}
{% block head %}
    <style>
        .nav_ul li{
            float: left;
            list-style: none;
            margin: 25px;
            border-bottom: antiquewhite;
        }
    </style>
{% endblock %}

{% block main %}
    <h3><span class="alyphicon alyphicon-user" aria-hidden="true"></span>{{ user.username }}</h3>
    <ul class="nav nav-tabs">
        <li role="presentation"><a href="{{ url_for('usercenter',user_id = user.id,tag = '1') }}">所有问答</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增长tag参数
 <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>app

base.html函数

<a href="{{ url_for('usercenter',user_id = user.id,tag=1) }}">{{ user.username }}</a>

index.htmlurl

<a href="{{ url_for('usercenter',user_id = foo.author_id,tag=1)}}">{{ foo.author.username }}评论{{ foo.comments|length }}</a>

detail.htmlspa

<a href="{{ url_for('usercenter',user_id=foo.author.id,tag = 1) }}">{{ foo.author.id }}</a>
相关文章
相关标签/搜索