# 前言 在大學和碩士期間主要都是接觸深度學習和電腦視覺的方面的研究,但最近慢慢發現,除了要會這些,許多公司也更重視如何把模型的結果接上後端的API或APP來做使用。但我對製作API或APP是完全沒有概念的,所以這是開始學習製作API和APP的第一天。 這是我的學習紀錄,所有範例都是跟著[Book_Python Flask實作記錄](https://hackmd.io/GVo6X6LoS3GNIW50LBJytw)的教學,並使用我自己的方法整理,以及加上自己的看法。 # 說明 上一個範例是透過```render_template```直接把html文件印在網頁上,而```render_template```也能傳遞參數至html文件,並呈現在網頁上 ```python= from flask import flask from flask import render_template # 固定格式 app = Flask(__name__) @app.route('/user/<username>') def render_para(username): return render_template('/abc2.heml', user_template=username) if __name__ == "__main__": app.run(debug=True) ``` 第9行中的```user_template```用來傳遞參數;而```username```為內容,內容來自路由 <br> - html文件也要跟著修改,需設置接收從後端傳過來的參數,透過```{{user_template}}```的方式接收 ```html= <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF_8"> <title> Hello Page </title> </head> <body> {{ user_template }} is building FLask APP </body> </html> ``` 結果如下圖所示 ![render_parameter](https://hackmd.io/_uploads/HyXbNiHJp.png =70%x) <br> [source Code Please Visit](https://github.com/ChrisCodeNation/How-to-Make-an-API-with-Flask-Course/blob/main/06_render_template2.py)