โดย MBMoo » 13/06/2020 3:18 pm
การเรียกใช้ ฟังก์ชั่น ใน class เดียวกัน พร้อมส่งค่า โดย โดย
Python ซึ่งจะใช้คู่กับ
Flask และทำการ return ค่า ออกมา โดยไม่ต้องใช้หน้า
html ด้วย ฟังก์ชั่น
redirect และ url_for
เริ่มจาก import
โค้ด: เลือกทั้งหมด
from flask import Flask, redirect, url_for
from flask_classful import FlaskView
สร้าง class และ ฟังก์ชั่น โดยให้ index เรียกใช้ show พร้อมส่งค่า หลังจากนั้นให้ show return ค่า ออกมา
โค้ด: เลือกทั้งหมด
class TestView(FlaskView):
def __init__(self):
self.action = "TEST"
def index(self):
return redirect(url_for('TestView:show',say='hi'))
def show(self,say):
return say
ผลลัพธ์
- Python Knowledge-1.png (12.49 KiB) Viewed 1532 times
หากต้องการศึกษาเรื่อง python หรือ Postgres และ psycopg2 เพิ่มเติม สามารถศึกษาได้จากในบนเรียนของ python vdo python
https://www.mindphp.com/vdo-tutorial-python.html
บทเรียน Python
https://www.mindphp.com/%E0%B8%9A%E0%B8 ... ython.html
วิธีการ เพิ่มข้อมูลลงฐานข้อมูล Postgres ด้วย Module psycopg2
viewtopic.php?f=144&t=67978
วิธีการ แก้ไขข้อมูลในฐานข้อมูล Postgres ด้วย Module psycopg2
viewtopic.php?f=144&t=67979
วิธีการ ลบข้อมูลออกจากฐานข้อมูล Postgres ด้วย Module psycopg2
viewtopic.php?f=144&t=67980
วิธีการ สร้างตารางข้อมูลในฐานข้อมูล Postgres ด้วย Module psycopg2
viewtopic.php?f=144&t=67983
การเรียกใช้ ฟังก์ชั่น ใน class เดียวกัน พร้อมส่งค่า โดย โดย [url=https://www.mindphp.com/%E0%B8%84%E0%B8%B9%E0%B9%88%E0%B8%A1%E0%B8%B7%E0%B8%AD/73-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3/2417-python-%E0%B8%84%E0%B8%B7%E0%B8%AD%E0%B8%AD%E0%B8%B0%E0%B9%84%E0%B8%A3.html]Python [/url] ซึ่งจะใช้คู่กับ [url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/python-framework-flask/6442-flask-framework-html-css-python.html]Flask[/url] และทำการ return ค่า ออกมา โดยไม่ต้องใช้หน้า [url=https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99-html.html]html[/url] ด้วย ฟังก์ชั่น
redirect และ url_for
เริ่มจาก import
[code]
from flask import Flask, redirect, url_for
from flask_classful import FlaskView
[/code]
สร้าง class และ ฟังก์ชั่น โดยให้ index เรียกใช้ show พร้อมส่งค่า หลังจากนั้นให้ show return ค่า ออกมา
[code]
class TestView(FlaskView):
def __init__(self):
self.action = "TEST"
def index(self):
return redirect(url_for('TestView:show',say='hi'))
def show(self,say):
return say
[/code]
ผลลัพธ์
[attachment=0]Python Knowledge-1.png[/attachment]
หากต้องการศึกษาเรื่อง python หรือ Postgres และ psycopg2 เพิ่มเติม สามารถศึกษาได้จากในบนเรียนของ python vdo python
https://www.mindphp.com/vdo-tutorial-python.html
บทเรียน Python
https://www.mindphp.com/%E0%B8%9A%E0%B8%97%E0%B9%80%E0%B8%A3%E0%B8%B5%E0%B8%A2%E0%B8%99%E0%B8%AD%E0%B8%AD%E0%B8%99%E0%B9%84%E0%B8%A5%E0%B8%99%E0%B9%8C/83-python.html
วิธีการ เพิ่มข้อมูลลงฐานข้อมูล Postgres ด้วย Module psycopg2 https://www.mindphp.com/forums/viewtopic.php?f=144&t=67978
วิธีการ แก้ไขข้อมูลในฐานข้อมูล Postgres ด้วย Module psycopg2 https://www.mindphp.com/forums/viewtopic.php?f=144&t=67979
วิธีการ ลบข้อมูลออกจากฐานข้อมูล Postgres ด้วย Module psycopg2 https://www.mindphp.com/forums/viewtopic.php?f=144&t=67980
วิธีการ สร้างตารางข้อมูลในฐานข้อมูล Postgres ด้วย Module psycopg2 https://www.mindphp.com/forums/viewtopic.php?f=144&t=67983