YWEIEN

导航

完成个人中心—导航标签

    1. 个人中心—视图函数带标签页面参数tag
      @app.route('/usercenter/<user_id>/<tag>')
      def usercenter(user_id, tag):
         if tag == ‘1':
             return render_template('usercenter1.html', **context)
      @app.route('/userr/<user_id>/<tag>')
      @log
      def userr(user_id,tag):
          user=User.query.filter(User.id == user_id).first()
          context ={
              'user':user,
              'questions': user.question,
              'comments':user.comments
          }
          if tag =='1':
              return render_template('center1.html',**context)
          elif tag == '2':
              return render_template('center2.html',**context)
          else:
              return render_template('center3.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 %}
          ha
      {% endblock %}
      {% block main %}
          <link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
      
      
      <ul class="nav nav-pills" style="margin-left: 30%">
          <li><a href="{{ url_for('userr',user_id=user.id,tag = 1) }}">全部问答</a></li>
          <li><a href="{{ url_for('userr',user_id=user.id,tag = 2) }}">全部评论</a></li>
          <li><a href="{{ url_for('userr',user_id=user.id,tag = 3) }}">个人资料</a></li>
      </ul>
      {% block ab %}{% endblock %}
      {% endblock %}

       

    3. 个人中心—有链接到个人中心页面的url增加tag参数
       <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
    4. base.html
       {% if username %}
                          <li><a href="{{  url_for('userr',user_id = session.get('id'),tag=1)}}">{{ session.get('user') }}</a></li>
                          <li><a href='{{ url_for('logout') }}'>注销</a></li>
                      {% else %}
                          <li><a href="{{ url_for('zhuce') }}"><span class="glyphicon glyphicon-user"></span> 注册</a></li>
                          <li><a href="{{ url_for('denglu') }}"><span class="glyphicon glyphicon-log-in"></span> 登录</a></li>
                      {% endif %}
      {% for foo in questions %}
                      <li class="list-group-item"style="width: 800px">
                          <img style="width: 30px" src="{{ url_for('static',filename='css/touxiang.jpg') }}" alt="64">
                          <a href="{{  url_for('userr',user_id = foo.author.id,tag='1') }}">{{ foo.author.username }}</a><br>
                          <a href="{{ url_for('detail',question_id=foo.id) }}">问题:{{ foo.title }}</a><br>
                          <p style="align-content: center">{{ foo.detail }}</p>
                          <span>评论数: ({{ foo.comments|length }})</span>
                          <span class="badge" style="margin-left: 60%">{{ foo.create_time }}</span>
                          <p style="margin-left: 25%"></p><br>
                      </li>
                  {% endfor %}

       

posted on 2017-12-20 14:57  YWEIEN  阅读(115)  评论(0编辑  收藏  举报