zoukankan      html  css  js  c++  java
  • 三十五、完成个人中心—导航标签

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

    @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>

    {% 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>

    base.html

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

    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.id }}</a>
  • 相关阅读:
    前端-【学习心得】-事件委托方法
    [方法] iOS时间戳的转换
    [封装] 修改NSString中部分字段的颜色
    Python3基础16——file对象测试数据的读写与操作
    Python3基础15—— 变量作用域
    Python3基础14——函数&内置函数
    Python3基础13——冒泡排序
    Python3基础12——while循环
    Python3基础11——打印三角形
    Python3基础10——切片(str和list)
  • 原文地址:https://www.cnblogs.com/Green-/p/8064701.html
Copyright © 2011-2022 走看看