Flask Documentation (1.1.x)Minimal Application What to do if the Server does not Start Debug Mode Routing Static Files Rendering Templates Accessing Request Data Redirects and Errors About Responses Sessions Message Flashing Logging Hooking Access the Database Blueprints and Views Templates Static Files Blog Blueprint Make the Project Installable Test Coverage Deploy to Production Keep Developing! Templates Jinja Setup Standard Context Standard when getting started. By convention, templates and static files are stored in subdirectories within the application’s Python source tree, with the names templates and static respectively. While this can0 码力 | 428 页 | 895.98 KB | 1 年前3
Flask Documentation (1.1.x). . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21 1.6 Templates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . when getting started. By conven- tion, templates and static files are stored in subdirectories within the application’s Python source tree, with the names templates and static respectively. While this can your application serves. • MarkupSafe comes with Jinja. It escapes untrusted input when rendering templates to avoid injection attacks. • ItsDangerous securely signs data to ensure its integrity. This is0 码力 | 291 页 | 1.25 MB | 1 年前3
Flask入门教程用的模板渲 染引擎——Jinja2 来完成。 按照默认的设置,Flask 会从程序实例所在模块同级目录的 templates 文件夹中寻 找模板,我们的程序目前存储在项目根目录的 app.py 文件里,所以我们要在项目 根目录创建这个文件夹: $ mkdir templates 模板基本语法 在社交网站上,每个人都有一个主页,借助 Jinja2 就可以写出一个通用的模板:{{ 第 3 章:模板 23 模板中使用的变量需要在渲染的时候传递进去,具体我们后面会了解。 编写主页模板 我们先在 templates 目录下创建一个 index.html 文件,作为主页模板。主页需要显 示电影条目列表和个人信息,代码如下所示: templates/index.html:主页模板 过滤器来获取 movies 的长度,类似 Python 里的 len() 函数。 第 3 章:模板 24 提示 访问 http://jinja.pocoo.org/docs/2.10/templates/#list-of-builtin-filters 查看所有 可用的过滤器。 准备虚拟数据 为了模拟页面渲染,我们需要先创建一些虚拟数据,用来填充页面内容: app.py:定义虚拟数据
0 码力 | 127 页 | 7.62 MB | 1 年前3
共 3 条
- 1













