การที่ Browser ของเราจะส่ง POST request เราต้องสร้าง สร้าง input attribute เอาไว้ในใน method ปรับเปลี่ยนที่ ists/templates/home.html และ Browser ส่งคำขอ POST ไปยัง server ของเราได้
Processing a POST Request on the Server
เพิ่ม POST request ใน unit test (lists/tests.py) และ check return HTML ที่ส่งกลับมา ว่ามี new item text ในนั้นรึป่าว
รูปที่ 1 Django DEBUG page showing CSRF error
แก้โค้ด HTML run : python3 funtional_tests.py
รูปที่ 2 Django DEBUG page showing CSRF error
แก้โค้ด HTMLimport Time run : python3 funtional_tests.py
Wiring Up Our Form to Send a POST Request
จากรูปที่ 2 แจ้งเตือนว่าไม่มีความปลอดภัย ใน Django จะใช้ CSRF Token
แก้โค้ด home.html เพิ่ม token run : python3 funtional_tests.py
รูปที่ 3 Show error : New to-do item did not appear in table
remove the time.sleep ใน funtional_tests.py
Processing a POST Request on the Server
เพิ่ม request method ใน unit test
เพิ่ม return ใน view.py
Passing Python Variables to Be Rendered in the Template
เพิ่ม object ใน template/home.py
แก้ไข lists/views.py
run :



ไม่มีความคิดเห็น:
แสดงความคิดเห็น