[問題] python 檔案上傳

看板Python作者 (非常念舊)時間9年前 (2015/01/21 11:11), 9年前編輯推噓0(002)
留言2則, 2人參與, 最新討論串1/2 (看更多)
http://ppt.cc/uuqN 我有一個上傳頁面.html,內容有 <html> <form action=upload_file method="post"> <input type="file" name="file"> <input type="submit" value="Send files" /> <form> </html> ------------------------------------------------------------------------- 主程式 def allowed_file(filename): return '.' in filename and \ filename.rsplit('.', 1)[1] in ALLOWED_EXTENSIONS ---> 這個 function 是用來判定傳進去的 filename 的附檔名是不是符合 ALLOWED_EXTENSION裡的元素,傳回 True or False @app.route('/', methods=['GET', 'POST'])-->這個路徑在客戶端是顯示甚麼..??? def upload_file(): if request.method == 'POST': file = request.files['file'] if file and allowed_file(file.filename): --> filename從哪裡傳進去阿?? filename = secure_filename(file.filename) file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename)) return redirect(url_for('uploaded_file', filename=filename)) return ''' <!doctype html> <title>Upload new File</title> <h1>Upload new File</h1> <form action="" method=post enctype=multipart/form-data> <p><input type=file name=file> <input type=submit value=Upload> </form> ''' 謝謝。 -- ※ 發信站: 批踢踢實業坊(ptt.cc), 來自: 60.251.223.31 ※ 文章網址: https://www.ptt.cc/bbs/Python/M.1421809898.A.A24.html ※ 編輯: gn00618777 (118.163.147.121), 01/21/2015 11:54:59

01/21 12:42, , 1F
建議還是先會寫 HTML 再來
01/21 12:42, 1F

01/21 13:20, , 2F
OK,用 html 簡單多了,謝謝。
01/21 13:20, 2F
文章代碼(AID): #1KlnZgea (Python)
文章代碼(AID): #1KlnZgea (Python)