# 前言 在大學和碩士期間主要都是接觸深度學習和電腦視覺的方面的研究,但最近慢慢發現,除了要會這些,許多公司也更重視如何把模型的結果接上後端的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) ``` 結果如下圖所示  <br> [Source Code Please Visit](https://github.com/ChrisCodeNation/How-to-Make-an-API-with-Flask-Course/blob/main/05_render_template.py)
×
Sign in
Email
Password
Forgot password
or
Sign in via Google
Sign in via Facebook
Sign in via X(Twitter)
Sign in via GitHub
Sign in via Dropbox
Sign in with Wallet
Wallet (
)
Connect another wallet
Continue with a different method
New to HackMD?
Sign up
By signing in, you agree to our
terms of service
.