แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ 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] เปิด

กระทู้แนะนำ
   

มุมมองที่ขยายได้ กระทู้แนะนำ: แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ

Re: แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ

โดย bom_002 » 20/03/2017 3:19 pm

File GET Data File upload.py

โค้ด: เลือกทั้งหมด

data = 'name='+image_filename
request = Request.from_values(query_string='foo=bar&blah=blafasel',content_length = len(data), input_stream = StringIO(data),
content_type = 'http://localhost:5002/',method = 'POST')
    


File Show GET Data File view.py

โค้ด: เลือกทั้งหมด

    
UPLOAD_FOLDER = '/home/com003/PycharmProjects/test_project/work01/'

def view_file(req, file_img=None):
    print  UPLOAD_FOLDER
    #print req.method
    if request.method == 'POST':
        file_img = request.form['name']
        print  'user = '+file_img
        return file_img

    file = UPLOAD_FOLDER +file_img
    print  'file = '+file

    f = open(file,'r')
    return BaseResponse(wrap_file(req.environ, f), mimetype='image/x-png',
                        direct_passthrough=True) #wrap_file(req.environ, f) ฟังก์ชันตัวมันเองไว้จัดการไฟล์ที่ upload เข้ามา โดยรับ paramiter จาก f = req.files['uploaded_file']
                        
def application(environ, start_response):
    req = BaseRequest(environ)
    #if req.method == 'POST':
    resp = view_file(req)
    return resp(environ, start_response)

if __name__ == '__main__':
    run_simple('localhost', 5002, application, use_debugger=True)
ผลการรันหน้าเว็บ
444.png
444.png (4.57 KiB) Viewed 850 times
ผลการรันหน้า view.py เกิด error
555.png
555.png (21.55 KiB) Viewed 850 times

Re: แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ

โดย mindphp » 18/03/2017 8:43 pm

ลองศึกษาต่อที่นี่
http://werkzeug.pocoo.org/docs/0.11/quickstart/
หัวข้อม Enter Request

แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ

โดย bom_002 » 18/03/2017 8:41 pm

ถ้าต้องการ ส่งค่า get_img ไปยังอีกฟอร์มต้องเขียนโค้ดยังไงครับ
จากฟอร์ม upload.py

โค้ด: เลือกทั้งหมด

get_img =  image1.png
ไปฟอร์ม view.py

โค้ด: เลือกทั้งหมด

show = get_img

ข้างบน