av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

創(chuàng)新互聯(lián)Python教程:python怎么實現(xiàn)文件上傳界面

本文章代碼上傳在碼云上

成都創(chuàng)新互聯(lián)公司,為您提供重慶網(wǎng)站建設、成都網(wǎng)站制作、網(wǎng)站營銷推廣、網(wǎng)站開發(fā)設計,對服務成都火鍋店設計等多個行業(yè)擁有豐富的網(wǎng)站建設及推廣經(jīng)驗。成都創(chuàng)新互聯(lián)公司網(wǎng)站建設公司成立于2013年,提供專業(yè)網(wǎng)站制作報價服務,我們深知市場的競爭激烈,認真對待每位客戶,為客戶提供賞心悅目的作品。 與客戶共同發(fā)展進步,是我們永遠的責任!

代碼地址

[email protected]:DanYuJie/upanddown.git

這里我們使用flask框架,簡單實用

目錄結構:
upandown/
    static/
        css/
        js/
            jquery.min.js
            toastr.min.js
    templates/
            index.html
    test.py

相關推薦:《python基礎教程》

首先我們需要一個頁面在templates/index.html(這里使用form表單實現(xiàn))




    
    
    
    
    
    
    Document


    
        
        
        
    
              

然后是后臺接收

test.py

#!/usr/bin/env python
# -*- coding:utf-8 -*-
from flask import Flask,render_template, request, send_from_directory,jsonify, redirect
import os
# import sys
# reload(sys)
# sys.setdefaultencoding('utf-8')
app = Flask(__name__)
# ALLOWED_EXTENSTIONS = set(['png', 'jpg', 'jpeg', 'gif'])
app.config['UPLOAD_FOLDER'] = os.getcwd()
download_floder = app.config['UPLOAD_FOLDER'] + '/upload'
def allow_file(filename):
    allow_list = ['png', 'PNG', 'jpg', 'doc', 'docx', 'txt', 'pdf', 'PDF', 'xls', 'rar', 'exe', 'md', 'zip'] 
    a = filename.split('.')[1]
    if a in allow_list:
        return True
    else:
        return False
@app.route('/main')
def home():
    return render_template('index.html')
@app.route('/getlist')
def getlist():
    file_url_list = []
    file_floder = app.config['UPLOAD_FOLDER'] + '/upload'
    file_list = os.listdir(file_floder)
    for filename in file_list:
        file_url = url_for('download',filename=filename)
        file_url_list.append(file_url)
    # print file_list
    return jsonify(file_list)
@app.route('/download/')
def download(filename):
    return send_from_directory(download_floder,filename, as_attachment=True)
@app.route('/upload', methods=['POST', 'GET'])
def upload():
    file = request.files['file']
    if not file:
        return render_template('index.html', status='null')
    # print type(file)
    if allow_file(file.filename):
        file.save(os.path.join(app.config['UPLOAD_FOLDER']+'/upload/', file.filename))
        return render_template('index.html', status='OK')
    else:
        return 'NO'
if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0')

網(wǎng)頁名稱:創(chuàng)新互聯(lián)Python教程:python怎么實現(xiàn)文件上傳界面
網(wǎng)頁路徑:http://uogjgqi.cn/article/djcgggg.html
掃二維碼與項目經(jīng)理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網(wǎng)交流