您好,登錄后才能下訂單哦!
flask.py
from flask import Flask, render_template, request, redirect, url_for from werkzeug.utils import secure_filename from os import path app = Flask(__name__) @app.route('/') def hello_world(): return render_template('index.html', title='Welcome') @app.route('/services') def services(): return 'Servisce' @app.route('/about') def about(): return 'About' @app.route('/user/<int:user_id>') def user(user_id): return 'User %d' % user_id @app.route('/login', methods=['GET', 'POST']) def login(): if request.method == 'POST': username = request.form['username'] password = request.form['password'] else: username = request.args['username'] return render_template('login.html', method=request.method) @app.route('/upload', methods=['GET', 'POST']) def upload(): if request.method == 'POST': file = request.files['file'] basepath = path.abspath(path.dirname(__file__)) upload_path = path.join(basepath, 'static/uploads') filename = secure_filename(file.filename) file.save(path.join(upload_path,filename)) return redirect(url_for('upload')) return render_template('upload.html') if __name__ == '__main__': app.run(debug=True)
upload.html
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h2>文件上傳實(shí)例</h2> <form action="" method="post" enctype="multipart/form-data"> <p> <input type="file" name="file"> <input type="submit" value="Upload"> </p> </form> </body> </html>
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請(qǐng)聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。