Flask学习笔记-- 4
来源:互联网 发布:黑格尔的哲学思想知乎 编辑:程序博客网 时间:2024/06/07 10:06
上篇笔记记录了Renderig Templates,index()视图函数返回的响应是一个index.html 的模板。
这篇笔记中在index.html 模板中添加CSS 和JavaSript,定义网页样式。
from flask import Flask,render_templateapp = Flask(__name__)@app.route('/')def index(): return render_template("index.html")@app.route('/<name>')def hello(name): return "Hello,%s" % nameif __name__ == "__main__": app.run(debug=True)
网页显示了index.html 中的内容:
Version 6
昨天看了一些css,JavaScript 内容。
可以添加CSS、JavaScript文件到代码中来定义网页样式。
Bootstrapcdn网站中有CSS和JavaScript 文件链接,可以拿过来直接用到自己写的代码中,不用自己写CSS 和JavaScript 文件啦
(1)在index.html的head标签中间添加link标签,href属性粘贴Bootstrapcdn网站中的CSS文件链接;
在boby标签中间添加script标签,src 属性粘贴href属性粘贴Bootstrapcdn网站中的Javascript文件链接。
(昨天笔记中有详细介绍link标签和script标签。)
<!DOCTYPE html> <html> <head> <title>FlaskApp</title> <link rel="stylesheet" type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"> </head> <body> <div> <p>Use templates to write things nicely. </p> <br> <p>Notice that the title of the page turned into "FlaskApp"</p> </div> <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script> </body></html>
重新加载网页,发现网页字体发生了变化,文字和页面边界之间空白消失了(还有很多,暂时看不到)
Flask Web Development 书中有关于Bootstrap 的章节:
(1) Bootstrap is an open source framework from Twitter that provides user interface components to create clean and attractive web pages that are compatible with all modern web browsers.
(2) Bootstrap is a client-side framework, so the server is not directly involved with it.
All the server needs to do is provide HTML responses that the reference Bootstrap’s cascading style sheet (CSS) and JavaScript files and instantiate the desired components through HTML, CSS, and JavaScript code.
(3) The ideal place to do all this is in templates.
- Flask学习笔记-- 4
- Flask-SQLALchemy学习笔记
- Flask学习笔记-1
- Flask源码学习笔记
- flask学习笔记
- flask学习笔记(-模板)
- flask学习笔记(-数据库)
- flask学习笔记
- Flask--学习笔记-注册
- Flask学习笔记
- Flask 学习笔记
- Flask学习笔记 -- 1
- Flask学习笔记-- 2
- Flask学习笔记-- 3
- Flask学习笔记--5
- Flask学习笔记--6
- Flask学习笔记--7
- Flask学习笔记--8
- nginx启动重启与升级以及检测配置文件
- 1055. The World's Richest 解析
- 基于bootstrap的web登陆实例
- 二分搜索
- caffe学习之二----mnist集合训练及其测试
- Flask学习笔记-- 4
- 百练OJ:2800:垂直直方图
- 将本地工程上传到github
- 命运(hdu2571)
- 有关JavaScript中浅拷贝、深拷贝的简单研究
- 未知:选择困难症——题解+优先队列
- 当你打开一个网站的时候,都发生了什么
- typeof
- 51nod 1058 阶乘的位数