期末作品检查

Posted 林丹宜

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了期末作品检查相关的知识,希望对你有一定的参考价值。

1.期末作品检查:基本要求

    (1)检查时间:18最后四节课,上课之前必须全部完成,上课做基本部署就开始检查

    (2)方式:逐个运行演示,抽查代码

    (3)主题:选一个主题,整个网站风格统一,布局合理,尽量美观。

2.期末作品检查:必须完成:

    (1)网站父模板统一布局:头部导航条、底部图片导航、中间主显示区域布局

    (2)注册、登录、注销

    (3)发布、列表显示

    (4)详情页

    (5)评论、列表显示

    (6)个人中心

3.搜索,条件组合搜索一篇完整的博客

    1. 个人学期总结,总结Python+Flask+mysql的web建设技术过程,标准如下:
    2. (1)即是对自己所学知识的梳理
    1. (2)也可作为初学入门者的简单教程
    1. (3)也可作为自己以后复习的向导
    1. (4)也是一种向外展示能力的途径
    4.期末作品检查:加分功能
    (1)文章分类、显示
    (2)点赞、收藏
    (3)修改密码、头像、上传头像
    (4)我的
    (5)高级搜索
一、个人学期总结
一学期匆匆过去,从一个菜鸟到可以初步做一个简单的网页系统,这不仅是进步,更是挑战。 回想刚开始学这门课程,那个时候,还不了解Python语言是什么。在老师的教授下,从最开始的基础练习—用Python语言画简单的图案,慢慢地到制作web页面。
真的感概一步一个脚印,
慢慢积累知识的重要性。
   俗话说:活到老学到老,我们要继续努力,抓紧自己的学习。知识无止境,探索无止境,人的发展亦无止境。在今后的日子里,我仍然要不断地充实自己,争取在所学领域有所作为。 脚踏实地,认真严谨,实事求是的学习态度,

 

二、作品展示——维尼熊主题
 (一)前期准备
1.连接数据库
import os
SQLALCHEMY_DATABASE_URI = \'mysql+pymysql://root:@127.0.0.1:3306/mis15?charset=utf8\'
SQLALCHEMY_TRACK_MODIFICATIONS = False
SECRET_KEY =os.urandom(24)

   2.创建表储存数据

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(200), nullable=False)#内部使用

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\'))

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()

   3.定义函数

@app.route(\'/\')#添加装饰器
def base():
    return render_template("base.html")

@app.context_processor
def mycontext():
    username=session.get(\'user\')
    if username:
        return {\'username\':username}
    else:
        return{}

@app.route(\'/logout\')
def logout():
    session.clear()
    return redirect(url_for(\'base\'))

@app.route(\'/denglu/\', methods=[\'GET\', \'POST\'])
def denglu():
    if request.method == \'GET\':
        return render_template("denglu.html")
    else:
        username = request.form.get(\'username\')
        password = request.form.get(\'password\')
        user = User.query.filter(User.username == username).first()
        if user:
            if user.check_password(password):
                session[\'user\']=username
                session[\'userid\']=user.id
                session.permanent = True
                return redirect(url_for(\'index\'))
            else:
                return \'密码错误\'
        else:
            return \'用户名不存在\'

@app.route(\'/zhuce/\', methods=[\'GET\', \'POST\'])
def zhuce():
    if request.method == \'GET\':
        return render_template("zhuce.html")
    else:
        username = request.form.get(\'username\')
        password = request.form.get(\'password\')
        user = User.query.filter(User.username == username).first()
        if user:
            return \'用户名已存在\'
        else:
            user = User(username=username, password=password)
            db.session.add(user)  # 数据库,添加操作
            db.session.commit()
            return redirect(url_for(\'denglu\'))

def log(func):
    @wraps(func)
    def wrapper(*args,**kwargs):
        if session.get(\'user\'):
            return func(*args,**kwargs)
        else:
            return redirect(url_for(\'denglu\'))
    return wrapper


@app.route(\'/question/\',methods=[\'GET\',\'POST\'])
@log
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
        user = User.query.filter(User.username == session.get(\'user\')).first()
        question=Question(title=title,detail=detail,author_id=author_id)
        question.author = user
        db.session.add(question)#保存到数据库
        db.session.commit()#提交
        return redirect(url_for(\'index\'))

@app.route(\'/index\')
def index():
    context={
        \'questions\': Question.query.all(),
    }
    return render_template(\'index.html\',**context)

@app.route(\'/detail/<question_id>\')
@log
def detail(question_id):
    quest=Question.query.filter(Question.id==question_id).first()
    return render_template("detail.html",ques=quest)
    return question_id

@app.route(\'/comment/\',methods=[\'GET\',\'POST\'])
@log
def comment():
    if request.method == \'GET\':
        return render_template("detail.html")
    else:
        comment = request.form.get(\'new_comment\')
        ques_id = request.form.get(\'question_id\')
        author_id = User.query.filter(User.username == session.get(\'user\')).first().id
        comm = Comment(author_id=author_id,question_id=ques_id,detail=comment)
        db.session.add(comm)  # 保存到数据库
        db.session.commit()  # 提交
        return redirect(url_for(\'detail\',question_id =ques_id))

@app.route(\'/usercenter/<user_id>/<tag>\')
@log
def usercenter(user_id,tag):
    user=User.query.filter(User.id==user_id).first()
    context={
        \'username1\':user.username,
        \'questions\':user.questions,
        \'comments\':user.comments,
        \'id\':user.id
    }
    if tag == \'1\':
        return render_template(\'usercenter.html\', **context)
    elif tag == \'2\':
        return render_template(\'user1.html\', **context)
    else:
        return render_template(\'user2.html\',**context)

@app.route(\'/search/\')
def search():
    qu=request.args.get(\'q\')
    ques=Question.query.filter(
        or_(
            Question.title.contains(qu),
            Question.detail.contains(qu),
        )
    )
    return render_template(\'index.html\',questions=ques)
(二)代码及展示
1.进入网站——父模板
主要代码:
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% block title %}
       {% endblock %}维尼乐园</title>

<link rel="stylesheet" type="text/css" href="{{ url_for(\'static\',filename=\'css/20.css\') }}">
<script src="{{ url_for(\'static\',filename=\'js/on_off.js\') }}"></script>
  </head>
{% block head %}
{% endblock %}

<body id="mybody" background="../static/images/background.jpg" style="width:100%;height: 100%;" >
<header class="navbar-wrapper">
    <div class="navbar navbar-black">
        <div class="container cl">
        <form action="{{ url_for(\'search\') }}" method="get" style="text-align: center;float: right;">
            <input name="q" type="text" placeholder="搜索从这里开始..." style="width: 180px;padding-left:14px;height: 28px;border: 2px solid #7BA7AB;border-radius: 5px;outline: none;background: #F9F0DA;color: #9E9C9C;">
            <button type="submit"  style="width: 55px;height: 31px;border: none;background: #7BA7AB;border-radius: 0 5px 5px 0;cursor: pointer;">查找</button>
        </form>
            <nav class="nav navbar-nav nav-collapse" role="navigation" id="Hui-navbar">
                <ul class="cl">
                    <li><a class="logo navbar-logo f-l mr-10 hidden-xs" href="{{ url_for(\'index\') }}" style="color: royalblue;text-decoration:none;">首页</a></li>
                    <li><span class="logo navbar-slogan f-l mr-10 hidden-xs">简单 &middot; 快乐 &middot; 维尼世界</span></li>
                {% if username %}
                    <li><a href="{{ url_for(\'usercenter\',user_id=session.get(\'userid\'),tag=1) }}" style="color: royalblue;text-decoration:none;">{{ username }}</a></li>
                    <li><a href="{{ url_for(\'logout\') }}"style="color: royalblue;text-decoration:none;">注销</a></li>
                {% else %}
                    <li><a href="{{ url_for(\'denglu\')}}"style="color: royalblue;text-decoration:none;">登录</a></li>
                    <li><a href="{{ url_for(\'zhuce\') }}"style="color: royalblue;text-decoration:none;">注册</a></li>
                {% endif %}
                    <li><a href="{{ url_for(\'question\') }}"style="color: royalblue;text-decoration:none;">发布问答</a></li>
                </ul>
            </nav>
        </div>
{% block main %}
    <div class="container-fluid">
        <img src="../static/images/5.png" style="width: 620px;height: 500px;position:absolute;right:0px;top:50px;" >
        <img src="../static/images/3.png" style="width: 320px;height: 250px;position:absolute;left:0px;top:350px;" >
    </div>
    <footer class="footer mt-20" >
            <div class="weini" >
                <img src="../static/images/41.jpg" style="width: 100px;height: 100px;top: 100px;"  >
                <img src="../static/images/10.jpg" style="width: 100px;height: 100px;top: 100px;"  >
                <img src="../static/images/14.jpg" style="width: 100px;height: 100px;top: 100px;"  >
                <img src="../static/images/55.jpg" style="width: 100px;height: 100px;top: 100px;"  >
                <img src="../static/images/66.jpg" style="width: 100px;height: 100px;top: 100px;"  >
                <nav> <a href="https://book.douban.com/subject/10773252/" target="_blank">维尼的烦恼</a>
                    <span class="pipe"><img src="../static/images/111.png" style="width: 30px;height: 30px;" ></span> <a href="http://www.4399er.com/xzt/gszt/xxwnsqgs/" target="_blank">小猪的笑容</a>
                    <span class="pipe"><img src="../static/images/111.png" style="width: 30px;height: 30px;" ></span> <a href="http://dy.163.com/v2/article/detail/CCT2TF3R05298ID3.html" target="_blank">快乐的维尼</a>
                    <span class="pipe"><img src="../static/images/111.png" style="width: 30px;height: 30px;" ></span> <a href="http://www.iqiyi.com/a_19rrjul0zx.html" target="_blank">维尼的日常</a>
                    <span class="pipe"><img src="../static/images/111.png" style="width: 30px;height: 30px;" ></span> <a href="http://www.baike.com/wiki/%E7%BB%B4%E5%B0%BC%E7%86%8A" target="_blank">小猪的幼稚</a>
                </nav>
            </div>
        </footer>
    </div>
    </div>
    </header>
    </body>
    </html>
{% endblock %}

 

  2.注册

主要代码:

{% extends \'base.html\' %}
{% block title %}
注册
{% endblock %}
{% block head %}

<link rel="stylesheet" type="text/css" href="{{ url_for(\'static\',filename=\'css/denglu.css\') }}">
<script src="../static/js/zhuce.js"></script>
{% endblock %}
{% block main %}
<body>
<img src="../static/images/3.png" style="width: 320px;height: 250px;position:absolute;left:0px;top:350px;" >
<img src="../static/images/5.png" style="width: 620px;height: 500px;position:absolute;right:0px;top:250px;" >
 <div class="box">
    <div class="titulo">Regist</div>
     <form class="form" method="post" action="{{ url_for(\'zhuce\') }}">
       <div class="input_box1"  >
          <input id="uname" name="username" type="text"  placeholder="请输入用户名" >
       </div>
       <div class="input_box2">
           <input id="upass" name="password" type="password"   placeholder="请输入密码">
       </div>
       <div class="input_box2">
          <input id="upass1" name="password" type="password"   placeholder="请确认密码" >
       </div>
       <div id="error_box"><br></div>
       <div class="input_box3" >
         <button onclick="return myLogin()"><img src="../static/images/call.png" style="width: 30px;height: 30px"></button>
       </div>
     </form>
 </div>
</body>
{% endblock %}

  3.登录

 主要代码:

{% extends \'base.html\' %}
{% block title %}
    登录
{% endblock %}
{% block head %}

<link href="../static/css/denglu.css" rel="stylesheet" type="text/css">
  <script src="../static/js/zhuce.js"></script>
{% endblock %}
{% block main %}
<body>
<img src="../static/images/3.png" style="width: 320px;height: 250px;position:absolute;left:0px;top:350px;" >
<img src="../static/images/5.png" style="width: 620px;height: 500px;position:absolute;right:0px;top:250px;" >
 <div class="box">
    <div class="titulo">Login</div期末作品检查

期末作品检查

期末作品检查

期末作品检查

期末作品检查

期末作品检查