หน้า 1 จากทั้งหมด 1
แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ
โพสต์แล้ว: 18/03/2017 8:41 pm
โดย bom_002
ถ้าต้องการ ส่งค่า get_img ไปยังอีกฟอร์มต้องเขียนโค้ดยังไงครับ
จากฟอร์ม upload.py
ไปฟอร์ม view.py
Re: แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ
โพสต์แล้ว: 18/03/2017 8:43 pm
โดย mindphp
Re: แนะนำตัวอย่างการ GET ค่าไปยังอีกฟอร์ม ของ python หน่อยครับ
โพสต์แล้ว: 20/03/2017 3:19 pm
โดย bom_002
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 (4.57 KiB) Viewed 861 times
ผลการรันหน้า view.py เกิด error
- 555.png (21.55 KiB) Viewed 861 times