@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.htmlcss
{% 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 %}
{% 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 %}
base.htmlhtml
<!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.htmlbootstrap
{% 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.htmlsession
{% 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.htmlapp
{% 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 %}