การเรียกใช้ ฟังก์ชั่น ใน class เดียวกัน พร้อมส่งค่า โดย python

ตอบกระทู้

รูปแสดงอารมณ์
:icon_plusone: :like: :plusone: :gfb: :-D :) :( :-o 8O :? 8) :lol: :x :P :oops: :cry: :evil: :twisted: :roll: :wink: :!: :?: :idea: :arrow: :| :mrgreen: :angry: :baa: :biggrin:
รูปแสดงอารมณ์อื่นๆ

BBCode เปิด
[img] เปิด
[url] เปิด
[Smile icon] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: การเรียกใช้ ฟังก์ชั่น ใน class เดียวกัน พร้อมส่งค่า โดย python

การเรียกใช้ ฟังก์ชั่น ใน class เดียวกัน พร้อมส่งค่า โดย python

โดย 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
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

ข้างบน