[Raspberry] Triển khai Web application trên Raspberry Pi Part 4

Bài này mình sẽ tiếp tục hướng dẫn các bạn cấu hình từng bước, các bạn thực hiện theo mình nhé.

1. Tạo thư muc:
 root@raspberrypi:/var/www/lab_app# mkdir templates  

2.
 root@raspberrypi:/var/www/lab_app# cd templates  

3. Chỉnh sửa file:
 root@raspberrypi:/var/www/lab_app/templates# gedit hello.html   

4. Copy nội dung của file trong này vào trong file hello.html

5. Chỉnh sửa file:
 root@raspberrypi:/var/www/lab_app# gedit hello.py  

6. Copy nội dung ở dưới vào trong file hello.py
 from flask import Flask  
 from flask import render_template  
 app = Flask(__name__)  
 app.debug = True  
 @app.route("/")  
 def hello():  
   return render_template('hello.html', message="Hello World!")  
 if __name__ == "__main__":  
   app.run(host='0.0.0.0', port=8080)  

7.

Open server:
 root@raspberrypi:/var/www/lab_app# python hello.py  

Mở browser và nhập vào địa chỉ http://ipraspberry:8080

Bài sẽ dừng ở đây. Hẹn bạn part tiếp theo nhé !!!

Bài đăng phổ biến từ blog này

Stack And Queue Trong Python

Review Sách 23 Thói quen chống lại sự trì hoãn