首页 > 其他 > 详细

期末作品检查

时间:2018-01-06 21:41:40      阅读:461      评论:0      收藏:0      [点我收藏+]
  • 个人学期总结

  • 本学期学习了近几年比较热门的python,发现python相对Java要简单也有趣很多,完成同一个任务,C语言要写1000行代码,Java只需要写100行,而Python可能只要20行。学习python比较容易入门。Python具有面向对象,解释型,丰富和强大的库,优雅,明确,简单等特点。当然也存在运行速度慢和不能加密的缺点。课程分为两部分,前一部分主要是python的基本操作,包括输入输出,基本数据类型,运算,turtle库,循环,条件,函数定义,字符串操作,词频统计等等。后一部分才是重难点,主要是web开发基础,需要我们熟悉掌握网页结构,HTML基础,CSS基础,JavaScript基础,链接到数据库等等。本次网页设计将这一学期所学的web开发基础的知识用到了具体的实践中去,深化了理论知识,同时也锻炼了动手实践能力。在这一个学期里,我查阅了许多有关网页设计的相关的资料,结合自己的经验,网页设计中出现许多小问题。但是由于不细心在具体实践中却浪费了不少时间,看来平时还是要多多实践才是。通过本次网页设计我锻炼了自己的实践能力,通过实践我也深刻的体会到网页设计的艰辛及问题解决后的喜悦心情,培养我的独立思考问题的能力,同时也增强了我的理论联系实际的能力,这为自己以后的工作奠定了良好的基础。本网页设计还存在许多的缺陷和不足之处,比如很多细节上做的还不行,画面比较简约,有些功能模块还应再加强。希望在以后的时间里,我可以把这些缺陷都弥补过来,进一步完善网页设计。
  1. 总结Python+Flask+MysqL的web建设技术过程,标准如下:
  2. 即是对自己所学知识的梳理
  3. 也可作为初学入门者的简单教程
  4. 也可作为自己以后复习的向导
  5. 也是一种向外展示能力的途径

开始flask项目

from flask import Flask
from flask_sqlalchemy import SQLAlchemy
import config
from flask import Flask, render_template, request, redirect, url_for,session
from functools import wraps
from datetime import datetime
from sqlalchemy import or_, and_

app = Flask(__name__)
app.config.from_object(config)

db = SQLAlchemy(app)

class User(db.Model):
    __tablename__ = user
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    username = db.Column(db.String(20), nullable=False)
    password = db.Column(db.String(20), nullable=False)
    nickname = db.Column(db.String(20))
db.create_all()

class Question(db.Model):
    __tablename__ = question
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    title = db.Column(db.String(100), nullable=False)
    detail = db.Column(db.Text, nullable=False)
    creat_time= db.Column(db.DateTime,default=datetime.now)
    author_id=db.Column(db.Integer,db.ForeignKey(user.id))
    author=db.relationship(User,backref=db.backref(questions))
db.create_all()

class Comment(db.Model):
    __tablename__ = comment
    id = db.Column(db.Integer, primary_key=True, autoincrement=True)
    author_id = db.Column(db.Integer, db.ForeignKey(user.id))
    question_id=db.Column(db.Integer, db.ForeignKey(question.id))
    detail = db.Column(db.Text, nullable=False)
    creat_time = db.Column(db.DateTime, default=datetime.now)
    question=db.relationship(Question,backref=db.backref(comments,order_by=creat_time.desc))
    author = db.relationship(User, backref=db.backref(comments))

db.create_all()

@app.route(/)
def base():
    return render_template(base.html)

@app.route(/index/)
def index():
    context = {
            questions:Question.query.order_by(-creat_time).all()

        }

    return render_template(index.html,**context)

@app.route(/login/,methods=[GET,POST])
def login():
    if request.method == GET:
        return render_template(login.html)
    else:
        usern = request.form.get(username)
        passw = request.form.get(password)
        user = User.query.filter(User.username == usern).first()
        if user:
            if user.password==passw:
                session[user] = usern
                session[userid] = user.id
                session.permanent = True
                return redirect(url_for(base))
            else:
                return upassword error
        else:
            return upassword is not existed

@app.route(/regist/,methods=[GET,POST])
def regist():
    if request.method==GET:
        return render_template(regist.html)
    else:
        usern=request.form.get(username)
        passw=request.form.get(password)
        nickn=request.form.get(nickname)
        user=User.query.filter(User.username==usern).first()
        if user:
            return uusername existed
        else:
            user=User (username=usern,password=passw,nickname=nickn)
            db.session.add(user)
            db.session.commit()
            return redirect(url_for(login))

def loginFirst(func):
    @wraps(func)
    def wrapper(*args, ** kwargs):
        if session.get(user):
            return func(*args, ** kwargs)
        else:
            return redirect(url_for(login))
    return  wrapper

@app.route(/question/,methods=[GET,POST])
@loginFirst
def question():
    if request.method==GET:
        return render_template(question.html)
    else:
        title = request.form.get(title)
        detail = request.form.get(detail)
        author_id = User.query.filter(User.username == session.get(user)).first().id
        question = Question(title=title, detail=detail, author_id=author_id)
        db.session.add(question)
        db.session.commit()
        return redirect(url_for(index))

   
@app.route(/detail/<question_id>)
def detail(question_id):

    quest = Question.query.filter(Question.id == question_id).first()
    return render_template(detail.html, ques=quest)


@app.route(/comment/,methods=[POST]) @loginFirst def comment(): detail = request.form.get(fabu) author_id = User.query.filter(User.username == session.get(user)).first().id quest_id =request.form.get(question_id) pinglun = Comment(question_id=quest_id,detail=detail, author_id=author_id) db.session.add(pinglun) db.session.commit() return redirect(url_for(detail,question_id=quest_id)) @app.route(/usercenter/<user_id>/<tag>) @loginFirst def usercenter(user_id,tag): user=User.query.filter(User.id== user_id).first() context={ user:user } 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) @app.context_processor def mycontext(): usern=session.get(user) if usern: return{username:usern} else: return{} @app.route(/search/) def search(): qu=request.args.get(q) ques=Question.query.filter(or_(Question.title.contains(qu),Question.detail.contains(qu))).order_by(-creat_time) return render_template(index.html, questions=ques) @app.route(/logout/) def logout(): session.clear() return redirect(url_for(index)) if __name__ == __main__: app.run(debug=True)

 连接数据库

import  os
SECRET_KEY = os.urandom(24)
SQLALCHEMY_DATABASE_URI = mysql+pymysql://root:569472176@127.0.0.1:3306/mis_db?charset=utf8
SQLALCHEMY_TRACK_MODIFICATIONS = False

 技术分享图片

父模板

<!DOCTYPE HTML>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>{% block title %}首页{% endblock %}</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">

{% block head %}{% endblock %}
<body id="mybody">

    <nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark"style="opacity:0.8;">
        <div class="collapse navbar-collapse" id="navbarSupportedContent">
            <ul class="navbar-nav mr-auto">
                <li class="nav-item"><a class="navbar-brand"
                    href="{{ url_for(‘index‘) }}">首页&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                <li class="nav-item active"><a class="navbar-brand"
                    href="{{ url_for(‘question‘) }}">发布问答&nbsp;&nbsp;&nbsp;&nbsp;</a></li>
                <li class="nav-item active"><a class="navbar-brand"
                    href="https://www.dji.com/cn/products/consumer?site=brandsite&from=nav">消费级产品</a></li>
                <li class="nav-item active"><a class="navbar-brand"
                    href="https://www.dji.com/cn/products/professional?site=brandsite&from=nav">专业级产品</a></li>
                 <li class="nav-item active"><a class="navbar-brand"
                    href="https://www.dji.com/cn/support?site=brandsite&from=nav">服务与支持</a></li>
                <form action="{{url_for(‘search‘)}}" method="get" class="form-inline" >
                    <input name="q" class="form-control mr-sm-2" type="search"
                        placeholder="请输入关键字"style="border-radius: 25px" >
                    <button class="btn btn-outline-success my-2 my-sm-0" type="submit">Search</button>
                </form>
            </ul>
            <nav class="navbar navbar-expand-lg navbar navbar-dark bg-dark">
                {% if username %} <a class="navbar-brand" href="{{ url_for(‘usercenter‘,user_id=session.get(‘userid‘),tag=1) }}">{{ session.get(‘user‘)
                    }}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                <a class="navbar-brand" href="{{ url_for(‘logout‘) }}">注销&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                    {% else %} <a class="navbar-brand" href="{{ url_for(‘login‘) }}">登陆&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                <a class="navbar-brand" href="{{ url_for(‘regist‘) }}">注册&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</a>
                {% endif %}
            </nav>
        </div>
    </nav>
<body background="https://stormsend1.djicdn.com/stormsend/uploads/75603600-92eb-0135-c4b0-12528100fbe3/P4P_.jpg"style="background-repeat:no-repeat;background-size: 100% 100%; background-attachment: fixed;">
    {% block main %} {% endblock %}
      <div id="footer">
                <div class="footerNav" style="text-align: center;position:fixed; left:0px; bottom:0px; width:100%; height:50px; z-index:9999">
                     <a rel="nofollow" href="https://www.dji.com/cn/company?site=brandsite&from=footer">关于我们</a> | <a rel="nofollow" href="https://www.dji.com/cn/terms?site=brandsite&from=footer">服务条款</a> | <a rel="nofollow" href="https://www.dji.com/cn/sitemap?site=brandsite&from=footer">网站地图</a> | <a rel="nofollow" href="https://www.dji.com/cn/contact?site=brandsite&from=footer">联系我们</a>
                </div>
                <div class="copyRight" style="text-align: center;position:fixed; left:0px; bottom:0px; width:100%; height:30px; z-index:9999">
                    Copyright ?Mars版权所有
                </div>
            </div>
</body>
</body>
</html>

 技术分享图片

首页

{% extends ‘base.html‘ %}
{% block title %}
    首页
{% endblock %}
{% block head %}

     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
       <link rel="stylesheet" type="text/css"href="../static/css/index.css">

{% endblock %}
{% block main %}
    
  <div class="card-body">

<div class="card" style="width:60rem; margin:0 auto;opacity:0.9">

    <ul class="list-group list-group-flush">
{% for foo in questions %}

        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>

            <br>

            <h3><a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>

            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>

            <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id,tag=1) }}">{{ foo.author.username}}</a>
            <br>
        评论:{{ foo.comments|length }}
        </li>
        {% endfor %}
    </ul>
</div>
  <br>
<div class="#" >
        <div class="img" >
            <a href="http://www.dji.com/cn">
              <img src="https://img14.360buyimg.com/n7/jfs/t5977/17/185587587/108108/247ade15/5925b821N32b8bb9a.jpg"></a>
          <div class="desc"><a href="http://www.dji.com/cn">大疆“晓”Spark</a></div>

       </div>
        <div class="img">
        <a href="http://www.dji.com/cn">
              <img src="https://img10.360buyimg.com/n7/jfs/t3232/65/6215650755/81612/3a052265/58a27e59N05fb5fc2.jpg" ></a>
          <div class="desc"><a href="http://www.dji.com/cn">大疆“精灵”Phantom</a></div>

    </div>
        <div class="img">
        <a href="http://www.dji.com/cn">
              <img src="https://img14.360buyimg.com/n7/jfs/t4012/34/459557656/48075/11cf82d3/584fcc5cN056eb123.jpg" ></a>
          <div class="desc"><a href="http://www.dji.com/cn">大疆“御”Mavic Pro</a></div>

    </div>
        <div class="img">
        <a href="http://www.dji.com/cn">
              <img src="https://img10.360buyimg.com/n7/jfs/t2278/130/1443161174/71119/87b96780/565edd23N23d203bc.jpg"></a>
          <div class="desc"><a href="http://www.dji.com/cn">大疆“悟”Inspire</a></div>
    </div>
</div>
<div class="clearfloat" style="text-align: center">
      <img src="https://img14.360buyimg.com/n7/jfs/t5977/17/185587587/108108/247ade15/5925b821N32b8bb9a.jpg">
      <img src="https://img10.360buyimg.com/n7/jfs/t3232/65/6215650755/81612/3a052265/58a27e59N05fb5fc2.jpg">
      <img src="https://img14.360buyimg.com/n7/jfs/t4012/34/459557656/48075/11cf82d3/584fcc5cN056eb123.jpg">
      <img src="https://img10.360buyimg.com/n7/jfs/t2278/130/1443161174/71119/87b96780/565edd23N23d203bc.jpg">
</div>
  </div>
{% endblock %}

首页CSS

img{
    width: 300px;
    height: 300px;
}
div.img{
    border: 1px solid black;
    width: 315px;
    height: 315px;
    float: left;
    margin: 5px;
}
div.img img{
    width: 100%;
    height: 80%;
}
div.desc{
    text-align: center;
    padding: 5px;
}
div.img:hover{
    border: 2px solid cornflowerblue;
}
.clearfloat{
    clear:both;
}

 技术分享图片

 

登录

{% extends ‘base.html‘ %}
{% block title %}登录{% endblock %}
{% block head %}
    <link href="{{ url_for(‘static‘,filename=‘css/login.css‘) }}" rel="stylesheet" type="text/css">
    <script src="{{ url_for(‘static‘,filename=‘js/login.js‘) }}"></script>
{% endblock %}
<body background="http://img2.imgtn.bdimg.com/it/u=1662655920,2109868634&fm=200&gp=0.jpg"></body>
{% block main %}
<div class="aa" style="opacity:0.8">
    <div class="login" ><h2>LOGIN</h2></div>
    <form action="{{ url_for(‘login‘) }}"method="post">
    <div class="aa1" >
        Username:<input id="name" type="text"name=‘username‘placeholder="请输入用户名"><br>
        Password:<input id="password" type="password"name=‘password‘placeholder="请输入密码"><br>
        </div>
        <div id="error_box"><br></div>
      <div class="aa2" >
         <button onclick="myLogin()">Login</button>
         <button type="button" onclick=window.alert("是否取消登录!")>Cancel</button>
<body background="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510743700&di=99ef867fd6c5a1386163e38f9d7b5f2c&imgtype=jpg&er=1&src=http%3A%2F%2Fstatic.leiphone.com%2Fuploads%2Fnew%2Farticle%2Fpic%2F201610%2F57fb516e1b62a.jpg%3Fwatermark%2F1%2Fimage%2FaHR0cDovL20uaWdhbzcuY29tL3Jlc1dlYi9pbWFnZXMvc2h1aXlpbi5wbmc%3D%2Fdissolve%2F80%2Fgravity%2FSouth%2Fdx%2F20%2Fdy%2F20"style="background-repeat:no-repeat;background-size: 100% 100%; background-attachment: fixed;"></body>

    </div>
        </form>
</div>

{% endblock %}

登录css

div{
    margin:0 auto;
    text-align:center;
    backgroup-color:blue
}
.aa{
    border:1px solid;
    border-radius:25px;
    width:380px;
    height:200px;
    background-color:#e3f2fd;
    margin-top:200px;
}
.login{
    font-size:20px;
    color: black;
    font-family:华文细黑;

}
.aa1{
    font-size:20px;
    font-weight:bold;
    color: red;
    font-family:华文细黑;
 }
.aa2{
    width:150px;
    height:60px;
    boder-style:hidden;
}

#error_box{
    color:red;
}
button {
    background-color:skyblue;
    border: none;
    color: white;
    padding: 9px;
    text-align: left;
    text-decoration: none;
    display: inline-block;
    font-size: 12px;
}

登录JS

function myLogin(){
            var uName=document.getElementById("name");
            var uError=document.getElementById("error_box");
            var upass = document.getElementById("password");
            var isError=true;
            uError.innerHTML = "<br>"
            //uname
            if(uName.value.length>12 || uName.value.length<6){
                uError.innerHTML="Username 6-12 bits";
                isError=false;
                return isError;
            }else if((uName.value.charCodeAt(0)>=48)&& uName.value.charCodeAt(0)<=57){
                uError.innerHTML="The first letter cannot be numeric";
                isError=false;
                return isError;
            }else for(var i=0; i<uName.value.length;i++){
                if((uName.value.charCodeAt(i)<48 || uName.value.charCodeAt(i)>57)&&(uName.value.charCodeAt(i)<97 || uName.value.charCodeAt(i)>122 )){
                    uError.innerHTML = "only letter or number.";
                    isNotError=false;
                    return isError;
                }
            }


            if(upass.value.length>12 || upass.value.length<6){
                uError.innerHTML="password 6-12 bits";
                isError=false;
                return isError;
            }
            return isError;


        }

 技术分享图片

 

注册

{% extends ‘base.html‘ %}
{% block title %}注册{% endblock %}
{% block head %}
    <link href="{{ url_for(‘static‘,filename=‘css/regist.css‘) }}" rel="stylesheet" type="text/css">
    <script src="{{ url_for(‘static‘,filename=‘js/regist.js‘) }}"></script>
{% endblock %}
{% block main %}
<div class="aa"style="opacity:0.8" >
    <div class="login" ><h2>Register</h2></div>
    <form action="{{ url_for(‘regist‘) }}"method="post">
    <div class="aa1" >
        <input id="name" type="text"placeholder="请输入用户名"name="username"><br>
        <input id="nickname" type="text"placeholder="昵称"name="nickname"><br>
        <input id="password" type="password"placeholder="请输入密码"name="password"><br>
        <input id="password1" type="password"placeholder="请再次输入密码"><br>

    </div>
        <div id="error_box"><br></div>
      <div class="aa2" >
         <button onclick="return myLogin()">Register</button>
<body background="https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1510743628&di=571738b7d2f56efdc88e82b5404a756e&imgtype=jpg&er=1&src=http%3A%2F%2Fimg0.pconline.com.cn%2Fpconline%2F1612%2F11%2F8637260_126a9835.jpg"style="background-repeat:no-repeat;background-size: 100% 100%; background-attachment: fixed;">
</body>
    </div>
        </form>
</div>
{% endblock %}

注册CSS

div{
    margin:0 auto;
    text-align:center;
    backgroup-color:blue
}
.aa{
    width:350px;
    height:250px;
    background-color:#e3f2fd;
    border:1px solid;
    border-radius:25px;
    margin-top:200px;
}
.login{
    font-size: 30px;
    color: black;
    font-family:华文细黑;

}
.aa1{
    font-size:18px;
    font-weight:bold;
    color: red;
    font-family:华文细黑;
    text-align:center;
 }
.aa2{
    width:150px;
    height:60px;
    boder-style:hidden;
}

#error_box{
    color:red;
}
button {
    background-color:skyblue;
    border: none;
    color: white;
    padding: 9px;
    text-align: left;
    text-decoration: none;
    display: inline-block;
    font-size: 12px;
}

注册JS

function myLogin(){
            var uName=document.getElementById("name");
            var uError=document.getElementById("error_box");
            var upass = document.getElementById("password");
            var uphone = document.getElementById("userphone");
            var upass1 = document.getElementById("password1");
            uError.innerHTML = "<br>"
            //uname
            if(uName.value.length>12 || uName.value.length<6){
                uError.innerHTML="Username 6-12 bits";
                return false;
            }else if((uName.value.charCodeAt(0)>=48)&& uName.value.charCodeAt(0)<=57){
                uError.innerHTML="The first letter cannot be numeric";
                return false;
            }else for(var i=0; i<uName.value.length;i++){
                if((uName.value.charCodeAt(i)<48 || uName.value.charCodeAt(i)>57)&&(uName.value.charCodeAt(i)<97 || uName.value.charCodeAt(i)>122 )){
                    uError.innerHTML = "only letter or number.";
                    return false;
                }
            }


            if(upass.value.length>12 || upass.value.length<6){
                uError.innerHTML="password 6-12 bits";
                return false;
            }
            if(upass.value != upass1.value){
                uError.innerHTML="The password input is inconsistent";
                return false;
            }
            if(uphone.value.length>11 || uphone.value.length<11){
                uError.innerHTML="phone number at least 11";
                return false;
            }
        return true
            window.alert("注册成功 !")

        }

 技术分享图片

发布问答

{% extends ‘base.html‘ %}
{% block title %}问答{% endblock %}
{% block head %}
    <link href="{{ url_for(‘static‘,filename=‘‘) }}" rel="stylesheet" type="text/css">
{% endblock %}
{% block main %}
       <br>
<section class="container">
    <div class="login" style="text-align: center;opacity:0.9">
        <label for="ask">Question</label>
         <form action="{{ url_for(‘question‘) }}" method="post">
        <textarea style="width:500px" type="password" rows="6" id="ask"  name="title"></textarea>
    <br>
    <div>
        <label for="questionDetail">Detail</label>
        <br>
        <textarea  rows="10" style="width:500px"id="questionDetail" type="password" name="detail"></textarea>
    </div>
    <br>
    <input type="checkbox">check me

    <input  type="submit" name="commit" value="发布">
         </form>
 </div>
           </section>

{% endblock %}

 技术分享图片

详情页

{% extends ‘base.html‘ %}
{% block title %}
    评论页
{% endblock %}
{% block head %}
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
{% endblock%}
{% block main %}
  <li class="card-body">
<div class="card" style="width:50rem; margin:0 auto;opacity:0.8">

    <ul class="list-group list-group-flush" style="height:100rem">

        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>

            <br>

            <h3>{{ ques.title }}</h3>

            <p>{{ ques.detail }}</p>
        <span class="badge"style="float:right">{{ ques.creat_time}}</span>

            <a href="">{{ ques.author.username}}</a>
        </li>
  <li class="list-group-item"style="height:10rem">

       <form action="{{ url_for(‘comment‘) }}" method="post">
        <textarea  rows="2" style="width:40rem"type="password" name="fabu"></textarea>
       <input name="question_id" type="hidden" value="{{ ques.id }}">
<br>
    <input  type="submit" name="commit" value="发布">
       </form>
      <br>
      <h4>评论:({{ ques.comments|length }})</h4>

<ul class="list-group list-group-flush">
{% for foo in ques.comments %}
        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>
            <br>
            <h3><a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>

            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>

            <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id,tag=1) }}">{{ foo.author.username}}</a>
        </li>
        {% endfor %}
    </ul>
</li>
    </ul>
</div>
</li>
  </div>
{% endblock %}

 技术分享图片

个人中心

{% extends ‘base.html‘ %}
{% block title %}
    个人中心
{% endblock %}
{% block head %}
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
{% endblock %}
{% block main %}
<div  style="width:50rem; margin:0 auto">
<ul class="list-group list-group-flush">
    <h2>{{ user.username }}</h2>
    </ul>
    <li role="presentation"class="btn btn-light"><a href="{{ url_for(‘usercenter‘,user_id=user.id,tag=‘1‘) }}">全部问答</a> </li>
    <li role="presentation"class="btn btn-light"><a href="{{ url_for(‘usercenter‘,user_id=user.id,tag=‘2‘) }}">全部评论</a> </li>
    <li role="presentation"class="btn btn-light"><a href="{{ url_for(‘usercenter‘,user_id=user.id,tag=‘3‘) }}">个人信息</a> </li>
</ul>
</div>
    {% block user %}
    {% endblock %}
{% endblock %}
{% extends ‘userbase.html‘ %}
{% block user %}
<div class="card" style="width:60rem; margin:0 auto;opacity:0.8">
<ul class="list-group list-group-flush">
<h3>全部问答</h3>
{% for foo in user.questions %}
        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>

            <br>

            <h3><a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>

            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>

            <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id,tag=1) }}">{{ foo.author.username}}</a>
        </li>
        {% endfor %}
</ul>
</div>
{% endblock %}
{% extends ‘userbase.html‘ %}
{% block user %}
<div class="card" style="width:60rem; margin:0 auto;opacity:0.8">
<ul class="list-group list-group-flush">
<h3>全部评论</h3>
{% for foo in user.comments %}
        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>
            <br>
            <h3><a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>
            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>
            <a href="">{{ foo.author.username}}</a>
        </li>
        {% endfor %}
    </ul>
</div>
{% endblock %}
{% extends ‘userbase.html‘ %}
{% block user %}
   <div class="card" style="width:60rem; margin:0 auto;opacity:0.8">
<h3>{{ username }}个人信息</h3>
<ul class="list-group list-group-flush">
        <li class="list-group-item">
            <span class="icon" aria-hidden="true">
                用户:{{ user.username }}<br>
                编号:{{ user.id }}<br>
                昵称:{{ user.nickname }}<br>
                文章篇数:{{ user.questions|length }}<br>
                评论数:{{ user.comments|length }}
            </span>
        </li>
    </ul>
</div>
{% endblock %}
{% extends ‘userbase.html‘ %}
{% block title %}
    个人信息页
{% endblock %}
{% block head %}
     <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css" integrity="sha384-PsH8R72JQ3SOdhVi3uxftmaW6Vc51MKb0q5P2rRUpPvrszuE4W1povHYgTpBfshb" crossorigin="anonymous">
{% endblock%}
{% block user %}
<div class="card" style="width:50rem; margin:0 auto">
<ul class="list-group list-group-flush" >
<h3>全部问答</h3>
{% for foo in user.questions %}
        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>
            <br>
            <h3> <a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>
            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>
            <a href="{{ url_for(‘usercenter‘,user_id=foo.author.id) }}">{{ foo.author.username}}</a>
        </li>
        {% endfor %}
</ul>
</div>
<br>
<br>
<div class="card" style="width:50rem; margin:0 auto">
<ul class="list-group list-group-flush">
<h3>全部评论</h3>
{% for foo in user.comments %}
        <li class="list-group-item">
            <span class="icon" aria-hidden="true"></span>
            <br>
            <h3> <a href="{{ url_for(‘detail‘,question_id=foo.id) }}">{{ foo.title }}</a></h3>
            <p>{{ foo.detail }}</p>
        <span class="badge"style="float:right">{{ foo.creat_time}}</span>
            <a href="">{{ foo.author.username}}</a>
        </li>
        {% endfor %}
    </ul>
</div>
<br>
<br>
   <div class="card" style="width:50rem; margin:0 auto">
<h3>{{ username }}个人信息</h3>
<ul class="list-group list-group-flush">
        <li class="list-group-item">
            <span class="icon" aria-hidden="true">
                用户:{{ user.username }}<br>
                编号:{{ user.id }}<br>
                昵称:{{ user.nickname }}<br>
                文章篇数:{{ user.questions|length }}<br>
                评论数:{{ user.comments|length }}
            </span>
        </li>
    </ul>
</div>
{% endblock %}

 技术分享图片

技术分享图片

技术分享图片

 

期末作品检查

原文:https://www.cnblogs.com/marsk/p/8214733.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!