期末作品检查

一篇完整的博客

  1. 个人学期总结
  2. 总结Python+Flask+MysqL的web建设技术过程,标准如下:
    1. 即是对自己所学知识的梳理
    2. 也可作为初学入门者的简单教程
    3. 也可作为自己以后复习的向导
    4. 也是一种向外展示能力的途径

 

 

一、个人学期总结

随着科学技术的发展和整个社会的进步,计算机技术也得到了很大的提高,特别是微型计算机的大范围普及,使计算机的应用逐渐由科学计算、实时控制等方面向非数值处理的各个领域中渗透并发挥着越来越重要的作用。尤其是以微型计算机为处理核心,以数据库管理系统为开发环境的管理系统在办公室自动化以及商业信息管理等方面的应用,日益受到人们的关注。本学期在杜老师的带领下,我们学习了管理信息系统这一门课程。管理信息系统由信息的采集、信息的传递、信息的储存、信息的加工、信息的维护和信息的使用六个方面组成。完善的管理信息系统MIS具有以下四个标准:确定的信息需求、信息的可采集与可加工、可以通过程序为管理人员提供信息、可以对信息进行管理。具有统一规划的数据库是MIS成熟的重要标志,它象征着管理信息系统MIS是软件工程的产物。信息是管理上的一项极为重要的资源,管理工作的成败取决于能否做出有效的决策,而决策的正确程度则在很大程度上取决于信息的质量。所以能否有效的管理信息成为企业的首要问题,管理信息系统在强调管理、强调信息的现代社会中越来越得到普及。

同时为符合现阶段IT程序设计里较新也较为热门的设计语言使用潮流,老师用了Python语言为我们引入了本门课程。众所周知,Python是一种面向对象的解释型计算机程序设计语言,是纯粹的自由软件且语法简洁清晰。Python具有丰富和强大的库。Python已经成为最受欢迎的程序设计语言之一。2011年1月,它被TIOBE编程语言排行榜评为2010年度语言。自从2004年以后,python的使用率呈线性增长。而在7月20日,IEEE发布2017年编程语言排行榜:Python高居首位。能紧跟风潮学习最热门的语言之一我想这一学期的我收获是满满的。当然了,要是仅仅靠在课堂上学习的知识,是绝对不够我们真正吃透理解和熟练应用这一门语言的,所以在我看来,课后自己要多多阅读相关书籍扩充自己对于这一门学科的其他专业知识面,走出课堂,使自己的实践和运用能力符合社会需要才是更为重要的。

二、总结Python+Flask+MysqL的web建设技术过程

1. 通过课程实操熟悉Python语言

理解管理信息系统:信息与数据、知识的区别;对管理信息系统的初步理解

http://www.cnblogs.com/laifai666/p/7477901.html

Python基础练习:输入输出简单的交互;输入圆的面积,并计算

http://www.cnblogs.com/laifai666/p/7495657.html

Turtle库基础练习:利用Turtle库画出各类图案,如:圆、同心圆、五角星等

http://www.cnblogs.com/laifai666/p/7511801.html

条件、循环、函数定义练习:通过条件函数语句的循环画出各类图案,如:太阳花、国旗等图案

http://www.cnblogs.com/laifai666/p/7516029.html

字符串基本操作:实现对字符串基本信息的输出;len(),eval(),+,*,in,chr(),转义\n\t\\;输出全部的星座符号

http://www.cnblogs.com/laifai666/p/7528264.html

凯撒密码、GDP格式化输出、九九乘法表:对凯撒密码进行编码;输出格式化GDP、九九乘法表

http://www.cnblogs.com/laifai666/p/7551013.html

英文词频统计预备,组合数据类型练习:对英文词频进行替换、转换大小写、统计操作;用字符串做增删改查询统计遍历操作

http://www.cnblogs.com/laifai666/p/7576472.html

组合数据类型练习,英语词频统计:建立学生学号成绩字典,做增删改查遍历操作;列表,元组,字典,集合的遍历及区别;英文词频统计实例

http://www.cnblogs.com/laifai666/p/7598997.html

文件方式实现完整的英文词频统计:对英文小说进行词频的分析

http://www.cnblogs.com/laifai666/p/7603612.html

中文词频统计:使用jieba库,进行中文词频统计,输出TOP20的词及出现次数;排除一些无意义词、合并同一词

http://www.cnblogs.com/laifai666/p/7610944.html

datetime处理日期和时间:日期格式间进行转换输出

http://www.cnblogs.com/laifai666/p/7614362.html

timestamp与timedalta,管理信息系统概念与基础:转换字符串为timestamp

http://www.cnblogs.com/laifai666/p/7646452.html

web基础:HTML基础,练习使用标签制作简单的页面

http://www.cnblogs.com/laifai666/p/7652088.html

web基础,用HTML元素制作web页面:

http://www.cnblogs.com/laifai666/p/7660452.html

导航,头部,CSS基础:制作导航条;HTML头部元素;行内样式表、内嵌样式表、外部样式表;练习定义三类选择器

 http://www.cnblogs.com/laifai666/p/7683075.html

CSS图片导航块:CSS选择器的灵活使用

http://www.cnblogs.com/laifai666/p/7701158.html

JavaScript基础,登录前端验证:<script></script>的三种用法;三种输出数据的方式;定义JS函数

http://www.cnblogs.com/laifai666/p/7724754.html

完成登录与注册页面前段:完成登录与注册页面的HTML+CSS+JS

http://www.cnblogs.com/laifai666/p/7762778.html

开始Flask项目:使用Flask中render_template,用不同的路径,返回首页、登录员、注册页

http://www.cnblogs.com/laifai666/p/7780518.html

夜间模式的开启与关闭,父模板的制作:

http://www.cnblogs.com/laifai666/p/7784485.html

加载静态文件,父模板的继承和扩展:用url_for加载静态文件

http://www.cnblogs.com/laifai666/p/7804266.html

管理信息系统的开发与管理:

http://www.cnblogs.com/laifai666/p/7823196.html

连接MySQL数据库,创建用户模型:安装与配置python3.6+flask+mysql数据库并创建用户模型

http://www.cnblogs.com/laifai666/p/7831779.html

通过用户模型,对数据库进行增删改操作:

http://www.cnblogs.com/laifai666/p/7850944.html

完成注册、登录功能,详细发布功能的制作:

http://www.cnblogs.com/laifai666/p/7874596.html

http://www.cnblogs.com/laifai666/p/7881016.html

http://www.cnblogs.com/laifai666/p/7911952.html

在首页添加显示问答的列表,并定义好相应的样式:

http://www.cnblogs.com/laifai666/p/7941259.html

首页列表显示全部问答,完成问题详情页布局:

http://www.cnblogs.com/laifai666/p/7988615.html

完成评论功能,评论列表显示及排序,个人中心显示:

http://www.cnblogs.com/laifai666/p/8033228.html

完成个人中心导航及导航标签:

http://www.cnblogs.com/laifai666/p/8068138.html

实现搜索功能、密码保护:

http://www.cnblogs.com/laifai666/p/8074397.html

http://www.cnblogs.com/laifai666/p/8085127.html

2.课程设计主要代码及样式展示

 连接数据库

import os

SQLALCHEMY_DATABASE_URI = 'mysql+pymysql://root:@127.0.0.1:3306/niub?charset=utf8'
SQLALCHEMY_TRACK_MODIFICATIONS = False

SECRET_KEY = os.urandom(24)

导入所用包及建立对象关系映射

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

from werkzeug.security import generate_password_hash, check_password_hash

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

    @property
    def password(self):   #外部使用
        return self._password

    @password.setter
    def password(self, row_password):
        self._password = generate_password_hash(row_password)

    def check_password(self, row_password):
        result = check_password_hash(self._password, row_password)
        return result

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

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'))
    creat_time = db.Column(db.DateTime, default=datetime.now)
    detail=db.Column(db.Text,nullable=False)
    question=db.relationship('Question',backref=db.backref('comments',order_by=creat_time.desc))
    author=db.relationship('User',backref=db.backref('comments'))

建立父模板及导航条

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>{% block title %}NEWS{% endblock %}</title>

    <script>
        function mySwitch(){
            var oBody = document.getElementById("myBody");
            var oOnOff = document.getElementById("myOnOff");
            if(oOnOff.src.match("on")){
                oOnOff.src="../static/img/off.jpg";
                oBody.style.background="black ";
                oBody.style.color="white";
            }else {
                oOnOff.src="../static/img/on.jpg";
                oBody.style.background="white";
                oBody.style.color="gray";
            }
        }
    </script>

{% block head %}
{#<link rel="stylesheet" type="text/css" href="../static/css/base.css">#}
{% endblock %}

</head>
<body bgcolor="#ffe4c4" id="myBody">

<nav>

    <a class="logo" href="http://127.0.0.1:5000/base2">
        <img src="{{ url_for("static",filename="img/ny.png") }}" alt="Logo" style="width: 100px;height: 35px"></a>
    <a href="http://127.0.0.1:5000/base2" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">首页</a>

      {% if username %}
       <a href="#" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">{{ username }}</a>
       <a href="{{ url_for('logout') }}" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">注销</a>
       <a href="{{ url_for('question') }}" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">菜谱分享</a>
      {% else %}
       <a href="{{ url_for('login') }}" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">登陆</a>
       <a href="{{ url_for('res') }}" style="text-decoration:none;color: darkgoldenrod;font-family: 'Arial Black';margin-left: 10px">注册</a>
{#       <a href="{{ url_for('usercenter') }}">{{ username }}</a>#}
      {% endif %}
<img id="myOnOff" onclick="mySwitch()" src="{{ url_for("static",filename="img/on.jpg") }} " style="width: 20px;height: 20px;margin-left: 10px" >

<form action="{{ url_for('search') }}" method="get" style="float: right;margin-top: 6px">
    <div class="form-group">
        <input name="q" type="text"  placeholder="请输入关键食材" style="margin: 5px"><button type="submit" style="text-decoration: none">搜索菜谱</button>
    </div>
</form>

</nav>

<hr>

{% block main %}{% endblock %}
</body>
</html>

建立登录注册界面

@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.check_password(passw):
                session['user'] = usern
                session['userid'] = user.id
                session.permanent = True
                return redirect(url_for("base2"))
            else:
                return u'用户密码错误!'
        else:
            return u'用户不存在!'

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


def loginFirst(func): #参数是函数,定义需要装饰器
    @wraps(func)
    def wrapper(*args, ** kwargs): #定义个函数将其返回
        print('call %s():' % func.__name__)
        if session.get('user'):
            return func(*args, ** kwargs)
        else:
            return redirect(url_for('login'))
    return wrapper #返回一个函数

登录后首页界面

{% extends 'base.html' %}
{% block title %}BASE{% endblock %}
{% block head %}
    <link rel="stylesheet" type="text/css" href="../static/css/base2.css">

{% endblock %}
{% block main %}
    <p>**{{ username }}**</p>
    <body class="bg">

 <div>
           <div class="img">
               <a href="http://www.chinacaipu.com/">
                   <img src="../static/img/1.jpg"></a>
               <div class="ab"><a href="http://www.chinacaipu.com/" style="text-decoration: none;color: saddlebrown">中国菜谱网</a></div>
           </div>

           <div class="img">
               <a href="http://www.ttmeishi.com/">
                   <img src="../static/img/2.jpg"></a>
               <div class="ab"><a href="http://www.ttmeishi.com/" style="text-decoration: none;color: saddlebrown">天天美食</a></div>
           </div>

           <div class="img">
               <a href="http://www.xiachufang.com/">
                   <img src="../static/img/5.jpg" style="height: 112px"></a>
               <div class="ab"><a href="http://www.xiachufang.com/" style="text-decoration: none;color: saddlebrown">下厨房</a></div>
           </div>

           <div class="img">
               <a href="http://www.beitaichufang.com/">
                   <img src="../static/img/3.jpg" style="height: 112px"></a>
               <div class="ab"><a href="http://www.beitaichufang.com/" style="text-decoration: none;color: saddlebrown">贝太厨房</a></div>
           </div>

           <div class="img">
               <a href="https://www.xinshipu.com/">
                   <img src="../static/img/4.jpg" style="height: 112px"></a>
               <div class="ab"><a href="https://www.xinshipu.com/" style="text-decoration: none;color: saddlebrown">心食谱</a></div>
           </div>

           <div class="img">
               <a href="http://www.meishichina.com/">
                   <img src="../static/img/6.jpg" style="height: 112px"></a>
               <div class="ab"><a href="http://www.meishichina.com/" style="text-decoration: none;color: saddlebrown">美食天下</a></div>
           </div>

            <div class="img">
               <a href="http://www.meishij.net/">
                   <img src="../static/img/7.jpg" style="height: 112px"></a>
               <div class="ab"><a href="http://www.meishij.net/" style="text-decoration: none;color: saddlebrown">美食杰</a></dv>
           </div>

 </div>
<br><br><br><br><br><br><br><br><br><br><br><br>

    {% for foo in question%}
     <div class="ak" style="margin-left: 10%">
        <div id="header" style="background-color: antiquewhite;width:1000px "><h2 align="center" style="margin-bottom:0;color: darkgoldenrod;">菜谱大杂烩</h2></div>
        <div id="content" style="background-color: beige;height:auto;width:1000px;float: left;">

        <ul class="alist" style="margin: 3px; list-style: none">
            <li id='001' class="list">
                <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                <p>菜品名:   <a href="{{ url_for('detail',question_id = foo.id) }}" style="text-decoration: none;color: darkgoldenrod">{{ foo.title }}</a></p>
                <p>用户名:   <a href="{{ url_for('usercenter',user_id = foo.author_id,tag =1) }}" style="text-decoration: none;color: darkgoldenrod">{{ foo.author.username }} 评论数:({{ foo.comments|length }})</a></p>
                <div>菜谱:{{ foo.detail }}</div>
                <span class="glyphicon glyphicon-leaf" aria-hidden="true"></span>
                <p style="align-content: center"><span class="badge" style="align:left">TIME:{{ foo.creat_time }}</span></p>
            </li>
        </ul>

        </div>
            <div id="footer" style="background-color: bisque;clear: both;text-align: center;width:1000px;color: darkgoldenrod; "><i>版权 @Doublewhere</i></div>
     </div>

    {% endfor %}

{% endblock %}

</body>

 

 发布问答页

{% extends 'base.html' %}
{% block title %}QUESTION{% endblock  %}
{% block head %}
    <link rel="stylesheet" type="text/css" href="../static/css/question.css">
{% endblock  %}
{% block main %}

<body class="allque">

        <div id="question-feedback" style="width:450px;margin-left: 25%">
        <div id="header" style="background-color: antiquewhite;margin-left: 20%;width: 450px"><h2 align="center" style="margin-bottom:0;"> 分享你的菜谱 </h2></div>
        <div id="content" style="background-color: beige;height:auto;width:450px;margin-left: 20%">

         <form action="{{ url_for('question') }}" method="post" >

   <div class="question-control" style="margin-left: 18%">

       <br><div><label for="question">菜名:</label><br>
            <textarea class="form-control" rows="6" id="questionTitle" placeholder="请输入菜品名"
                      style="height: 50px;width: 320px" name="title" ></textarea>
       </div>

       <div><label for="questionDetail">详细菜谱:</label><br>
            <textarea class="form-control" rows="6" id="questionDetail" placeholder="请输入详细菜谱"
                      style="height: 120px;width: 320px" name="detail"></textarea>
       </div>

       <input type="checkbox" style="margin-left: auto">菜谱反馈<br></div>

        <div class="submit-button" >
        <button type="submit" style="margin-left: 45%" id="submit-button">提交</button>
        </div>

        <br><div id="footer" style="background-color: bisque;clear: both;text-align: center;margin:auto"><i>版权 @Doublewhere</i></div>

</form>

</div>

 </div>
</body>

{% endblock  %}

详细问答评论页

{% extends 'base.html' %}
{% block title %}DETAIL{% endblock  %}
{% block head %}
    <link rel="stylesheet" type="text/css" href="../static/css/detail.css">
{% endblock  %}
{% block main %}

    <body class="allbg">

        <div id="question-feedback" style="width:730px ">
        <div id="header" style="background-color: antiquewhite; "><h2 align="center" style="margin-bottom:0;"> Q & A </h2></div>
        <div id="content" style="background-color: beige;height:auto;width:730px;float: left;"><br>


   <div class="question-control">

       <div style="margin-top: 10px;margin-left: 2%;border: dotted #ffdead;border-width: 2px;width: 700px;height: auto"><label for="question"> 标题:</label>{{ ques.title }}<br>
           <p style="margin-left: auto">用户:<small>{{ ques.author.username }}</small></p>
           <p style="margin-left: auto">评论:{{ ques.detail }}</p>
           <p style="margin-left: auto"><span class="badge" style="align:right"> 时间:{{ ques.creat_time }}</span></p>
       </div><br>

<form action="{{ url_for('comment') }}" method="post">
       <div style="margin-left: 2%"><label for="questionDetail">问答:</label><br>

            <textarea  class="form-control" rows="6" id="new-comment" placeholder="请输入详细问答" style="height: 120px;width: 700px" name="newcomment"></textarea><br>
                <input name="question_id" type="hidden" value="{{ ques.id }}">

       </div><br>

        <div class="submit-button" >
            <button type="submit" style="margin: auto;margin-left: 45%;align-items: center">提交</button><br>
        </div>
</form>
       <br><div id="footer" style="background-color: bisque;clear: both;text-align: center;margin:auto"><i>版权 @Doublewhere</i></div>

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

        <div id="header" style="background-color: antiquewhite;margin-left: 50%"><h2 align="center" style="margin-bottom:0;"> 评论区 </h2></div>
        <div style="margin-left: 52%;color: saddlebrown;">评论数:({{ ques.comments|length }})</div>

           <ul class="list-group" style="margin-left: 52%">
       {% for foo in ques.comments %}
            <li class="list-group-item" type="hidden" style="list-style: none" >
                <span class="glyphicon glyphicon-heart-empty" aria-hidden="true"></span>
                <a href="{{ url_for('usercenter',user_id=foo.author_id ,tag=1)}}" style="text-decoration: none;">◇用户:{{ foo.author.username }}</a>
                <p style="float: right">◆评论:({{ foo.comments|length }})<p/><br>
                <p>★ 详细评论:{{ foo.detail }}</p><br>

                <span class="badge" style="margin-left: 60%">评论时间:{{ foo.creat_time }}</span>
                <p style="margin-left: 25%"></p>
            </li>
       {% endfor %}
            </ul>

</body>
{% endblock %}

用户个人中心页

{% extends 'base.html' %}
{% block title %}user{% endblock %}
{% block head %}
         <style>
          .nav_ul li{
           list-style:none;
             float:left;
             margin:20px;
         }
         </style>
{% endblock %}
{% block main %}
        <ul class="nav_ul">
             <li role="presentation"><a href="{{ url_for('usercenter',user_id = user.id,tag = '1') }}" style="text-decoration:none;color: #b82c73;font-family: 'Arial Black';">全部菜谱</a></li>
             <li role="presentation"><a href="{{ url_for('usercenter',user_id = user.id,tag = '2') }}" style="text-decoration:none;color: #315b8b;font-family: 'Arial Black';">全部评论</a></li>
             <li role="presentation"><a href="{{ url_for('usercenter',user_id = user.id,tag = '3') }}" style="text-decoration:none;color: #45b88c;font-family: 'Arial Black';">个人资料</a></li>
        </ul>
    {% block user %}{% endblock %}
{% endblock %}

 

posted @ 2018-01-06 19:19  杜丽晖  阅读(115)  评论(0编辑  收藏  举报