企业🤖AI Agent构建引擎,智能编排和调试,一键部署,支持私有化部署方案 广告
模板实例化需要导入 `render_template`方法 ``` from flask import render_template ``` 通过 `render_template` 我们可以直接渲染模板输出 ``` return render_template("index.html") ``` 示例: 改造下 `app/api_1_0/controller` 下的 `index.py` 控制器使其渲染模板输出 ``` #!/usr/bin/env python3 # -*- encoding: utf-8 -*- from app.api_1_0 import bp from flask import render_template @bp.route('/', methods=['GET']) def index(): return render_template("api/index.html") ``` 在 `app/templates/api` 目录下新建 `index.html` ,录入如下代码 ``` <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title>Flask</title> </head> <body> <h1>Hello Flask!!!</h1> </body> </html> ``` 测试 ![hello_flask](https://img.kancloud.cn/6b/e8/6be87f9951fc617cb42fc76995655b9b_597x163.png)