# python flask 教學 ## 簡單class ```py= class 車子: def __init__(self,這台車有多少輪子): self.輪子數量=這台車有多少輪子 def 開門(self): print("開門~") ``` ## 最簡單的flask ```py= from flask import Flask app = Flask(__name__) @app.route('/') def hello_world(): return '你好,世界!' if __name__ == '__main__': app.run(host='0.0.0.0', debug=True) ``` ## render_template範例 [點我下載範例網頁](https://drive.google.com/file/d/1J019dIFEvvp9HOH66YYNMcmJLzOJYu8-/view?usp=sharing) ``` myapp/ ├── main.py # 主程式 └── /templates ├── 1.html # 網頁 ``` ```py= from flask import Flask, render_template app = Flask(__name__) @app.route('/') def welcome(): return render_template('1.html') if __name__ == '__main__': app.run(host='0.0.0.0', debug=True) ``` ## jinja2 範例 範例網頁 ```html= <!DOCTYPE html> <html> <head> <title> 測試網頁</title> </head> <body> <h1 style="font-size: 700%; text-align: center;"> {{ name }}</h1> </body> </html> ``` python 程式 ```py= from flask import Flask,render_template app = Flask(__name__) @app.route('/') def show_directory_name(): return render_template("2.html",name="賴威廷") if __name__ == '__main__': app.run(debug=True) ``` ## 完整版[點我下載](https://drive.google.com/file/d/1yzbmKB7QPvdvte0HhZDXTaxbWFARtesg/view?usp=sharing)
×
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
.