ขั้นตอนแรกใน สร้างโปรเจ็กขึ้นมาใหม่หนึ่งโปรเจ็กตั้งชื่ออะไรได้ สร้างโฟรเดอร์ไว้ในโปรเจ็ก คือ templates, static และ ไฟล์ python ดังนั้นจะได้ แล้วให้ทำการติดตั้ง Flask โดยการ pip install flask ใน terminal ของ pycharm ถ้าติดตั้งได้ถูกต้องจะขึ้นดังนี้
Successfully installed Jinja2-2.10.1 MarkupSafe-1.1.1 Werkzeug-0.15.4 click-7.0 flask-1.0.3 itsdangerous-1.1.0 ในโฟรเดอร์ templates ให้สร้างไฟล์ HTML ขึ้นมาก ส่วน static จะเป็นไฟล์ CSS, JS อยู่ภายในไฟล์ ในไฟล์ index.py ให้ทำการเรียกใช้ flask โดยใช้คำสั่ง
โค้ด: เลือกทั้งหมด
from flask import Flask, render_template
app=Flask(__name__)
@app.route('/')
def index():
return render_template("home.html")
if __name__ == '__main__':
app.run()
โค้ด: เลือกทั้งหมด
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<p>HELLO PYTHON</p>
</body>
</html>
https://www.mindphp.com/บทเรียนออนไลน์/python-framework-flask/6442-flask-framework-html-css-python.html