日韩无码专区无码一级三级片|91人人爱网站中日韩无码电影|厨房大战丰满熟妇|AV高清无码在线免费观看|另类AV日韩少妇熟女|中文日本大黄一级黄色片|色情在线视频免费|亚洲成人特黄a片|黄片wwwav色图欧美|欧亚乱色一区二区三区

RELATEED CONSULTING
相關(guān)咨詢(xún)
選擇下列產(chǎn)品馬上在線(xiàn)溝通
服務(wù)時(shí)間:8:30-17:00
你可能遇到了下面的問(wèn)題
關(guān)閉右側(cè)工具欄

新聞中心

這里有您想知道的互聯(lián)網(wǎng)營(yíng)銷(xiāo)解決方案
創(chuàng)新互聯(lián)Python教程:python怎么實(shí)現(xiàn)文件上傳界面

本文章代碼上傳在碼云上

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

代碼地址

git@gitee.com:DanYuJie/upanddown.git

這里我們使用flask框架,簡(jiǎn)單實(shí)用

目錄結(jié)構(gòu):
upandown/
    static/
        css/
        js/
            jquery.min.js
            toastr.min.js
    templates/
            index.html
    test.py

相關(guān)推薦:《python基礎(chǔ)教程》

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




    
    
    
    
    
    
    Document


    
        
        
        
    
              

然后是后臺(tái)接收

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')

當(dāng)前名稱(chēng):創(chuàng)新互聯(lián)Python教程:python怎么實(shí)現(xiàn)文件上傳界面
網(wǎng)站地址:http://m.5511xx.com/article/djcgggg.html