Flask框架之 - 简易静态网站 !

网站截图:

Python源代码如下:

# coding=utf-8
from flask import Flask,render_template

app = Flask(__name__)

@app.route("/",methods=["GET","POST"])
def home():
    return render_template("home.html")

@app.route("/chapter1",methods=["GET","POST"])
def chapter1():
    return render_template("chapter1.html")
@app.route("/chapter1/1.1",methods=["GET","POST"])
def chapter1_1():
    return render_template("1.1.html")
@app.route("/chapter1/1.2",methods=["GET","POST"])
def chapter1_2():
    return render_template("1.2.html")

@app.route("/chapter2",methods=["GET","POST"])
def chapter2():
    return render_template("chapter2.html")
@app.route("/chapter2/2.1",methods=["GET","POST"])
def chapter2_1():
    return render_template("2.1.html")
@app.route("/chapter2/2.2",methods=["GET","POST"])
def chapter2_2():
    return render_template("2.2.html")


if __name__ == '__main__':
    app.run(debug=True)

HTML代码: home

<!DOCTYPE html>
<html lang="en">
<head>
     <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>首页 - 陈彬的Python教程</title>

</head>
<body>
<h1>············································章节目录··················································</h1>
<a href=" http://127.0.0.1:5000/chapter1"><img src="/static/chapter1.jpg" width="1350" height="270" /></a> <br>
<br>
<a href=" http://127.0.0.1:5000/chapter2"><img src="/static/chapter2.jpg" width="1350" height="270" /></a> <br>

</body>
</html>

HTML代码: chapter1

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>第一章 - 陈彬的Python教程</title>
</head>
<body>
<h1><i>第一章</i></h1>
<a href=" http://127.0.0.1:5000/chapter1/1.1">1.1 Python简介</a> <br>
<br>
<a href="http://127.0.0.1:5000/chapter1/1.2" target="_blank">1.2 Python安装步骤</a> <br>
<br>
<br>
<br>
<a href="http://127.0.0.1:5000/">返回上一层</a> <br>
<br>
<br>
<br>
<a href=" http://www.baidu.com/" target="_blank">百度一下,你就知道!</a> <br>
<a href=" http://www.taobao.com/">淘宝网,淘你喜欢!</a> <br>
<br>


</body>
</html>

HTML代码: chapter2

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>第二章 - 陈彬的Python教程</title>
</head>
<body>
<h1><i>第二章</i></h1>
<a href="http://127.0.0.1:5000/chapter2/2.1">2.1 Python基础</a> <br>
<br>
<a href="http://127.0.0.1:5000/chapter2/2.2">2.2 Python函数</a> <br>
<br>
<br>
<br>
<a href="http://127.0.0.1:5000/">返回上一层</a> <br>
</body>
</html>

HTML代码: 1.1

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>1.1 Python简介-陈彬的Python教程</title>
</head>
<body>
<p>1.1 Python简介</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python是著名的“龟叔”Guido van Rossum在1989年圣诞节期间,为了打发无聊的圣诞节而编写的一个编程语言。 现在,全世界差不多有<br>
 <br>
  600多种编程语言,但流行的编程语言也就那么20来种。如果你听说过TIOBE排行榜,你就能知道编程语言的大致流行程度 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;当你用一种语言开始作真正的软件开发时,你除了编写代码外,还需要很多基本的已经写好的现成的东西,来帮助你加快开发进度。比如 <br>
 <br>
       说,要编写一个电子邮件客户端,如果先从最底层开始编写网络协议相关的代码,那估计一年半载也开发不出来。高级编程语言通常都会提供 <br>
 <br>
    一个比较完善的基础代码库,让你能直接调用,比如,针对电子邮件协议的SMTP库,针对桌面环境的GUI库,在这些已有的代码库的基础上 <br>
 <br>
    开发,一个电子邮件客户端几天就能开发出来。 <br>
<img src="/static/girl3.jpg" width="500" height="300" />  <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python就为我们提供了非常完善的基础代码库,覆盖了网络、文件、GUI、数据库、文本等大量内容,被形象地称作“内置电池(batteries <br>
 <br>
    included)”。用Python开发,许多功能不必从零编写,直接使用现成的即可。 <br>
 <br>
    除了内置的库外,Python还有大量的第三方库,也就是别人开发的,供你直接使用的东西。当然,如果你开发的代码通过很好的封装,也可以 <br>
 <br>
    作为第三方库给别人使用。 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;许多大型网站就是用Python开发的,例如YouTube、Instagram,还有国内的豆瓣。很多大公司,包括Google、Yahoo等,甚至NASA(美国 <br>
<br>
航空航天局)都大量地使用Python。 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;龟叔给Python的定位是“优雅”、“明确”、“简单”,所以Python程序看上去总是简单易懂,初学者学Python,不但入门容易,而且将来深入下 <br>
 <br>
    去,可以编写那些非常非常复杂的程序。 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;总的来说,Python的哲学就是简单优雅,尽量写容易看明白的代码,尽量写少的代码。如果一个资深程序员向你炫耀他写的晦涩难懂、动不 <br>
<br>
动就几万行的代码,你可以尽情地嘲笑他。 <br>
 <br>
首选是网络应用,包括网站、后台服务等等; <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;其次是许多日常需要的小工具,包括系统管理员需要的脚本任务等等; <br>
 <br>
另外就是把其他语言开发的程序再包装起来,方便使用。 <br>
 <br>
最后说说Python的缺点。 <br>
<img src="/static/girl4.jpg" width="500" height="300" /> <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;任何编程语言都有缺点,Python也不例外。优点说过了,那Python有哪些缺点呢? <br>
 <br>
第一个缺点就是运行速度慢,和C程序相比非常慢,因为Python是解释型语言,你的代码在执行时会一行一行地翻译成CPU能理解的机器码, <br>
 <br>
这个翻译过程非常耗时,所以很慢。而C程序是运行前直接编译成CPU能执行的机器码,所以非常快。 <br>
 <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;但是大量的应用程序不需要这么快的运行速度,因为用户根本感觉不出来。例如开发一个下载MP3的网络应用程序,C程序的运行时间 <br>
 <br>
需要0.001秒,而Python程序的运行时间需要0.1秒,慢了100倍,但由于网络更慢,需要等待1秒,你想,用户能感觉到1.001秒和1.1秒的区 <br>
<br>
别吗? <br>
 <br>
        这就好比F1赛车和普通的出租车在北京三环路上行驶的道理一样,虽然F1赛车理论时速高达400公里,但由于三环路堵车的时速只有20公里, <br>
 <br>
因此,作为乘客,你感觉的时速永远是20公里。 <br>
<br>
<br>
<br>
<a href=" http://127.0.0.1:5000/chapter1">返回上一层</a> <br>
<a href="http://127.0.0.1:5000/">回到首页</a> <br>
<br>
<br>
<br>
</body>
</html>

HTML代码: 1.2

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>1.2 Python安装步骤-陈彬的Python教程</title>
</head>
<body>
<p>1.2 Python安装步骤</p>
在Mac上安装Python <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果你正在使用Mac,系统是OS X 10.8~10.10,那么系统自带的Python版本是2.7。要安装最新的Python 3.6,有两个方法: <br>
方法一:从Python官网下载Python 3.6的安装程序(网速慢的同学请移步国内镜像),双击运行并安装; <br>
方法二:如果安装了Homebrew,直接通过命令brew install python3安装即可。 <br>
在Linux上安装Python <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;如果你正在使用Linux,那我可以假定你有Linux系统管理经验,自行安装Python 3应该没有问题,否则,请换回Windows系统。 <br>
对于大量的目前仍在使用Windows的同学,如果短期内没有打算换Mac,就可以继续阅读以下内容。 <br>
在Windows上安装Python <br>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;首先,根据你的Windows版本(64位还是32位)从Python的官方网站下载Python 3.6对应的64位安装程序或32位安装程序(网速 <br>
慢的同学请移步国内镜像),然后,运行下载的EXE安装包 <br>
<img src="/static/girl5.jpg" width="500" height="300" />
<br>
<br>
<br>


</body>
</html>

HTML代码: 2.1

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>2.1 Python基础-陈彬的Python教程</title>
</head>
<body>
<p>2.1 Python基础</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Python是一种计算机编程语言。计算机编程语言和我们日常使用的自然语言有所不同, <br>
最大的区别就是,自然语言在不同的语境下有不同的理解,而计算机要根据编程语言执行任务, <br>
就必须保证编程语言写出的程序决不能有歧义,所以,任何一种编程语言都有自己的一套语法, <br>
编译器或者解释器就是负责把符合语法的程序代码转换成CPU能够执行的机器码,然后执行。 <br>
Python也不例外。 <br>
<img src="/static/girl.jpg" width="200" height="300" />
&nbsp;&nbsp;&nbsp;&nbsp;<img src="/static/girl2.jpg" width="200" height="300" />
<br>
<br>
<br>
<a href=" http://127.0.0.1:5000/chapter2">返回上一层</a> <br>
<a href="http://127.0.0.1:5000/">回到首页</a> <br>

</body>
</html>

HTML代码: 2.2

<!DOCTYPE html>
<html lang="en">
<head>
    <link rel="icon" href="/static/title_pict.ico" type="img/x-ico" />
    <meta charset="UTF-8">
    <title>2.2 Python函数-陈彬的Python教程</title>
</head>
<body>
<p>2.2 Python函数</p>
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;在Python中,定义一个函数要使用def语句,依次写出函数名、括号、括号中的参数和冒号:,然后,在缩进块中编写函数体, <br>
函数的返回值用return语句返回。 <br>
我们以自定义一个求绝对值的my_abs函数为例: <br>
def my_abs(x): <br>
    if x >= 0: <br>
        return x <br>
    else: <br>
        return -x <br>
<img src="/static/girl6.jpg" width="400" height="300" />
<br>
<br>
<br>
<a href=" http://127.0.0.1:5000/chapter2">返回上一层</a> <br>
<a href="http://127.0.0.1:5000/">回到首页</a> <br>
</body>
</html>

HTML笔记:

*HTML标题: <h1>这是一个标题</h1> 最重要的(字体最大)
<h2>这是一个标题</h2> 次重要的
<h3>这是一个标题</h3> 次之
注: 浏览器会自动地在标题的前后添加空行。

*HTML段落: <p>这是一个段落</p>
<p>这是另外一个段落</p>

*换行: <br>

*空格: &nbsp # 右键折叠(folding), 折叠所有, 再展开所有, 空格部分就会全部被折叠起来.

*链接: <a href="http://www.runoob.com">这是一个链接</a>

*图像: <img src="/images/logo.png" width="258" height="39" />

*音乐: <embed src="/static/music.mp3" hidden="true" autostart="true" loop="true"> # <body></body>中添加
注释: hidden=true代表隐藏播放 , autostart=true代表自动播放 , loop=true代表循环播放

*水平线: <hr> 标签在 HTML 页面中创建水平线。

*注释: {# 注释内容 #}

*加粗: <b> 内容 </b>

*斜体: <i> 内容 </i>

*<ul></ul> : 无序列表
*<li></li> : 无序列表内的列表项

*html函数格式: {% 循环 %} {{ 内含变量 }} {# 注释 #}

猜你喜欢

转载自www.cnblogs.com/chenbin93/p/9002187.html
今日推荐