完成个人中心—导航标签

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

    2. 个人中心—导航标签链接增加tag参数
      <li role=“presentation”><a href=“{{ url_for(‘usercenter’,user_id = user.id,tag = ‘1’) }}">全部问答</a></li>

    3. 个人中心—有链接到个人中心页面的url增加tag参数
       <a href="{{ url_for('usercenter',user_id = session.get('userid'), tag=1) }}">{{ session.get('user') }}</a>
    4. @app.route('/usercenter/<user_id>/<tag>')
      @login_re
      def usercenter(user_id,tag):
          user=User.query.filter(User.id==user_id).first()
          context={
              # 'username':user.Username,
              # 'questions':user.question,
              # 'comments':user.comments
      
              'user':user
          }
          # return render_template('usercenter.html', **context)
          if tag == '1':
              return render_template('user1.html', **context)
          elif tag == '2':
              return render_template('user2.html', **context)
          else:
              return render_template('user3.html', **context)

       index.html

    5. {% extends 'base.html' %}
      
      {% block title %}首页{% endblock %}
      
      {% block head %}
          <link href="{{ url_for('static',filename='css/index.css') }}" rel="stylesheet" type="text/css">
          <script src="{{ url_for('static',filename='js/index.js') }}"></script>
      {% endblock %}
      
      {% block main %}
          <ul class="list-group" style="margin-left:20%;margin-top: 5%;margin-right:20%">
      {#    <li class="list-group-item">#}
      {#        <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>#}
      {#        <a href="{{ url_for('detail')}}">username</a>#}
      {#        <br>#}
      {#        <a href="#)"title></a>#}
      {#        <span class="badge">create_time</span>#}
      {#       <p>detauk</p>#}
              {% for foo in question %}
                      <li class="list-group-item" >
                      <a href={{ url_for('usercenter',user_id=foo.author_id,tag=1 )}}>{{ foo.author.username }} </a><br>
                          <a href={{ url_for('detail',question_id=foo_id)}}>{{ foo.title }}</a>
      
                          <span class="badge">{{ foo.creat_time }}</span>
                          <p class="abstract">{{ foo.detail }}</p>
                      </li>
              {% endfor %}
          </ul>
      <div>
          <div class="img">
              <a href="http://www.baidu.cn/">
               <img src="http://p3.so.qhimgs1.com/bdr/_240_/t015a62ea10ce841183.jpg"></a>
              <div align="center"><a href="http://www.baidu.cn/" >阿斯顿马丁</a></div>
          </div>
            <div class="img">
              <a href="http://www.baidu.cn/">
               <img src="http://p2.so.qhimgs1.com/bdr/_240_/t014017698c50318c42.jpg"></a>
              <div align="center"><a href="http://www.baidu.cn/">雪佛兰</a></div>
          </div>
             <div class="img">
              <a href="http://www.baidu.cn/">
               <img src="http://p5.so.qhimgs1.com/bdr/_240_/t01d01aca9f5db2159b.jpg"></a>
              <div align="center"><a href="http://www.baidu.cn/">兰博基尼</a></div>
          </div>
              <div class="img">
              <a href="http://www.baidu.cn/">
               <img src="http://p5.so.qhimgs1.com/bdr/_240_/t01fb87f1928a69d5eb.jpg"></a>
              <div align="center"><a href="http://www.baidu.cn/">奔驰</a></div>
          </div>
      </div>
      
      {% endblock %}

       

    6. userbase.html
      {% extends 'base.html' %}
      {% block title %}个人中心{% endblock %}
      
      {% block head %}
              <style>
                  .nav1 >li{
                      list-style: none;
                      float: left;
                      margin: 10px;
                  }
              </style>
      
      {% endblock %}
      
      {% block main %}
           <div class="nav1">
              <ul>
                  <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>
          </div>
          {% block user %}{% endblock %}
      {% endblock %}

       

    7. base.html

    8. <!DOCTYPE html>
      <html>
      <head>
          <meta charset="utf-8">
          <title>{% block title%}car{% endblock %}</title>
          <link href="{{ url_for('static',filename='css/base.css') }}" rel="stylesheet" type="text/css">
          <link rel="stylesheet" href="http://cdn.static.runoob.com/libs/bootstrap/3.3.7/css/bootstrap.min.css">
         <script src="{{ url_for('static',filename='js/base.js') }}"></script>
      {% block head %}
      
      
      {% endblock %}
          <style>
              nav navbar-nav li {
                  list_style: none;
                  float: left;
                  margin: 10px;
              }
      
              .nav1 li{
                      list-style: none;
                      float: left;
                      margin: 10px;
                  }
          </style>
      </head>
      <body id="mybody">
      
      <nav class="navbar" role="navigation" style="">
          <div class="container-fluid" id="container">
              <div class="navbar-header">
                  <a class="navbar-brand" href="{{ url_for('index') }}">首页</a>
              </div>
              <div>
                  <ul class="nav navbar-nav">
                      {% if username %}
                          <li><a href={{ url_for('usercenter',user_id=session.get('userid'),tag=1) }}>{{ username }}</a></li>
                          <li><a href="{{ url_for('logout') }}">注销 </a></li>
                      {% else %}
                      <li><a href="{{ url_for('login') }}" onclick="">登录</a></li>
                      <li><a href="{{ url_for('regist') }}" onclick="">注册</a></li>
                      {% endif %}
                      <li><a href="{{ url_for('lable') }}" onclick="">发布问答</a></li>
      
      
                  </ul>
              </div>
             <div style="float: right">
                 <img style="width: 50px; height: 50px" id="myonoff" onclick="mySwitch()" src="https://ps.ssl.qhimg.com/sdmt/119_135_100/t01ebad6510c93738fc.gif" style="width:50px" >
             </div>
              <div>
                  <input type="text" name="user" id="user" placeholder="请输入搜索关键词">
                  <input type="button" value="搜索" class="btn btn-success" onclick="">
              </div>
      {#    <body background="http://p5.so.qhimgs1.com/bdr/_240_/t01fb87f1928a69d5eb.jpg" style="width: 100%; height: 100%"></body>#}
      
          </div>
      </nav>
      {% block main %}{% endblock %}
      
      </body >
      </html>
      </body>

      user1.html

    9. {% extends 'userbase.html' %}
      
      {% block user %}
          {% block head %}
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/userbase.css') }}">
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/user.css') }}">
          {% endblock %}
          <div class="a1">
              <h3>{{ username }}<br>
                  <small>全部问答</small>
              </h3></div>
              <ul>
                  {% for foo in user.question %}
                      <li class="list-group-item" >
                      <a href="#">{{ foo.author.username }} </a><br>
                          <a href={{ url_for('detail',question_id=foo_id)}}>{{ foo.title }}</a>
      
                          <span class="badge">{{ foo.creat_time }}</span>
                          <p class="abstract">{{ foo.detail }}</p>
                      </li>
              {% endfor %}
              </ul>
          </div>
      
      {% endblock %}

      user2.html

      {% extends 'userbase.html' %}
      
      {% block user %}
          {% block head %}
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/userbase.css') }}">
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/user.css') }}">
          {% endblock %}
          <div class="a1">
              <h3>{{ username }}<br>
                  <small>全部评论</small>
              </h3></div>
              <ul>
                  {% for foo in user.comments %}
                      <li class="list-group-item" >
                      <a href="#">{{ foo.author.username }} </a><br>
                          <a href={{ url_for('detail',question_id=foo_id)}}>{{ foo.title }}</a>
      
                          <span class="badge">{{ foo.creat_time }}</span>
                          <p class="abstract">{{ foo.detail }}</p>
                      </li>
              {% endfor %}
              </ul>
          </div>

      user3.html

      {% extends 'userbase.html' %}
      
      {% block user %}
          {% block head %}
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/userbase.css') }}">
              <link rel="stylesheet" type="text/css" href="{{ url_for('static',filename='css/user.css') }}">
          {% endblock %}
      
          <div class="a1">
              <h3>{{ username}}<br>
                  <small>个人信息</small>
              </h3></div>
              <ul>
                  <li>用户:{{ username}}</li>
                  <li>文章篇数:</li>
      
              </ul>
      
      
      {% endblock %}

posted @ 2017-12-20 15:33  070王学竞  阅读(128)  评论(0编辑  收藏  举报