# 前言 在大學和碩士期間主要都是接觸深度學習和電腦視覺的方面的研究,但最近慢慢發現,除了要會這些,許多公司也更重視如何把模型的結果接上後端的API或APP來做使用。但我對製作API或APP是完全沒有概念的,所以這是開始學習製作API和APP的第一天。 這是我的學習紀錄,所有範例都是跟著[Book_Python Flask實作記錄](https://hackmd.io/GVo6X6LoS3GNIW50LBJytw)的教學,並使用我自己的方法整理,以及加上自己的看法。 # 說明 在01的範例中,可以透過return string將內容印在網頁上。但實際上不可能把整個HTML都跟python寫在一起,所以可以透過render_template來解決。 - 可以從flask直接import 進來 ```python= from flask import Flask from flask import render_template ``` 需建立一個templates資料夾,當使用render_tempplate的時候,flask就會先到templates資料夾尋找對應的html文件。 - abc.html ```html= <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF_8"> <title> Hello Page </title> </head> <body> Flask APP </body> </html> ``` - 接著就能透過render_template把html的模板印在網頁上了 ```python= # 固定格式 app = Flask(__name__) @app.route('/') def render(): return render_template('/abc.html') if __name__ == "__main__": app.run(debug=True) ``` 結果如下圖所示 ![render](https://hackmd.io/_uploads/S18igiB1a.png =70%x) <br> [Source Code Please Visit](https://github.com/ChrisCodeNation/How-to-Make-an-API-with-Flask-Course/blob/main/05_render_template.py)