说明:
- 本人的实验环境在云服务器(CentOS7操作系统)上,在VSCode软件上SSH远程连接云服务器进行代码编写
- 因为文章所有内容和代码是纯手敲的缘故,所以演示的代码可能跟武沛齐(据说是小猪佩奇的远房表哥)老师视频中的有所不同,但原理相同
目的: 开发一个平台 - 前端开发: HTML CSS JavaScript - 接收请求并处理 - Mysql数据库: 存储数据 快速上手: 基于Flask Web框架快速搭建一个网站 深入学习: 基于Django框架
python 安装 Flask web 框架
pip install flask
创建Flask的python目录
[root@hecs-33592 ~]# mkdir -p /root/python/FlaskWeb [root@hecs-33592 ~]# cd /root/python/FlaskWeb [root@hecs-33592 FlaskWeb]# pwd /root/python/FlaskWeb
创建一个名为web.py的python文件
from flask import Flask
app = Flask(__name__)
# 创建了网址 /show/info 和 函数index 的对应关系
# 以后用户在浏览器上访问 /show/info, 网站自动执行
@app.route("/show/info")
def index():
return "中国联通"
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5100, debug=False)
运行
[root@hecs-33592 ~]# /usr/bin/python3 /root/python/FlaskWeb/web.py

浏览器进行访问: http://[你的ip]:5100/show/info

这种 return 方式返回 HTML 内容的方式不方便进行管理,因此我们会引入templates模板
from flask import Flask, render_template
app = Flask(__name__)
# 创建了网址 /show/info 和 函数index 的对应关系
# 以后用户在浏览器上访问 /show/info, 网站自动执行
@app.route("/show/info")
def index():
# 默认去当前目录的 templates 文件夹中找
return render_template("index.html")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5100, debug=False)
创建templates目录
mkdir /root/python/FlaskWeb/templates/

编写index.html文件

Document
中国联通
重新运行Flask,浏览器刷新访问

当然这个templates目录也可以自定义名称
# 例如目录名称为"xxx" app = Flask(__name__, template_folder="xxx")
Document
一级标题
二级标题
三级标题
四级标题
五级标题
内容asd
这里就很有意思了,你可以选择跳转自己网站的地址,或者跳转外部的网站
我的联通
点击跳转自己的网站
点击跳转别人的网站百度
然后需要修改web.py文件
from flask import Flask, render_template
app = Flask(__name__)
# 创建了网址 /show/info 和 函数index 的对应关系
# 以后用户在浏览器上访问 /show/info, 网站自动执行
@app.route("/show/info")
def index():
# 默认去当前目录的 templates 文件夹中找
return render_template("index.html")
# 新添加如下配置
@app.route("https://blog.csdn.net/get/news")
def get_news():
# 默认去当前目录的 templates 文件夹中找
return render_template("get_news.html")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5100, debug=False)
在templates目录下新添加一个 get_news.html 文件
Document
我是内部链接
重新运行Flask,刷新页面

点击第一行后,跳转到如下页面
点击点击第二行后,跳转到百度
自行脑补百度页面哈
在新的 Tab 标签页打开链接
添加 target=“_blank”
我是内部链接

刷新浏览器

尝试访问服务器本地图片
在/root/python/FlaskWeb/下新建目录static
放入一张图片dog.jpg

修改get_news.html
我是内部链接
刷新浏览器

跟刚才一样
然后可以调整一下图片的高度与宽度
我是内部链接

- 块级标签 - - - 行内标签 - - -![]()
实现: 点击图片,跳转至指定页面
修改web.py,增加get_product
from flask import Flask, render_template
app = Flask(__name__)
# 创建了网址 /show/info 和 函数index 的对应关系
# 以后用户在浏览器上访问 /show/info, 网站自动执行
@app.route("/show/info")
def index():
# 默认去当前目录的 templates 文件夹中找
return render_template("index.html")
@app.route("https://blog.csdn.net/get/news")
def get_news():
return render_template("get_news.html")
@app.route("/get/product")
def get_product():
return render_template("get_product.html")
if __name__ == '__main__':
app.run(host='0.0.0.0', port=5100, debug=False)
在templates下新增一个get_product.html
Document
访问页面

点击图片进行url跳转

无序列表


有序列表
- 中国移动
- 中国联通
- 中国电信

修改web.py新增一个访问路径
@app.route("/get/table")
def get_table():
return render_template("get_table.html")
在templates页面下新建get_table.html文件
Document
| ID | 姓名 | 年龄 |
|---|---|---|
| 10 | 张三 | 20 |
| 11 | 李四 | 20 |
| 12 | 王五 | 20 |
| 13 | 赵六 | 20 |
重新运行并访问页面

为表格增加边框
| ID | 姓名 | 年龄 |
|---|---|---|

if (条件) {
https://blog.csdn.net/qq_43139145/article/details/...
}else{
https://blog.csdn.net/qq_43139145/article/details/...
}
if (条件) {
https://blog.csdn.net/qq_43139145/article/details/...
else if (条件){
https://blog.csdn.net/qq_43139145/article/details/...
}else{
https://blog.csdn.net/qq_43139145/article/details/...
}
function func(){
https://blog.csdn.net/qq_43139145/article/details/...
}
//执行
func()
DOM 是一个模块,模块可以对HTML页面中的标签进行操作
//根据 ID 获取标签
var tag = doucment.getElementById("xx");
//获取标签中的文本
tag.innerText
//修改标签中的文本
tag.innerText = "hhhhhhh";
如标题 6.3.2 中的案例
Document

还有很多的DOM操作没有介绍,我们后面会使用JQuery来实现DOM的功能,所以这里的内容了解即可
JQuery是一个JavaScript的第三方模块(第三方类库)
JQuery的安装方式参考本文的 5.8 Bootstrap实现动态效果
Document
中国联通

中国联通
中国联通
中国联通
JQuery操作:
$("#txt")
中国联通
中国联通
中国联通
JQuery操作:
$(".c1")
中国联通
中国联通
中国联通
JQuery操作:
$("h1")
123
JQuery操作:
$(".c1 .c2 h1")
123
123
- 456
JQuery操作:
$("#c1,#c2,li")
JQuery操作:
$("input[name='n1']")
北京上海深圳广州
JQuery操作:
$("#c1").prev() //上一个
$("#c1")
$("#c1").next() //下一个
$("#c1").next().next() //下一个的下一个
$("#c1").siblings() //所有的
北京浦东新区静安区奉贤区深圳广州北京上海深圳广州
JQuery操作:
$("#c1").parent() //父亲
$("#c1").parent().parent() //父亲的父亲
$("#c1").children() //所有的儿子
$("#c1").children(".p10") //所有的儿子中寻找class=p10
$("#c1").find(".p10") //所有的子孙中寻找class=p10
$("#c1").children("div") //所有的儿子中寻找标签 div
Document

功能升级: 只允许有一个是展开的
Document

内容
JQuery操作:
$("#c1").text() //获取文本内容
$("#c1").text("abc") //设置文本内容
$("#c2").val() //获取用户输入的值
$("#c2").val("嘿嘿嘿") //设置值
Document

在JQuery可以删除指定的标签
当页面框架加载完成之后执行代码
Document
| ID | 姓名 | 年龄 |
|---|---|---|
| 1 | poker | |
| 1 | poker | |
| 1 | poker | |
| 1 | poker |

Document
人员信息录入功能,需要提供用户信息:
- 用户名
- 年龄
- 薪资
- 部门
- 入职时间
…
对于时间的选择: 插件(datetimepicker),或者可以直接使用
Document
