您好,登錄后才能下訂單哦!
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>文件上傳實例</h2> <form action="" method="post" enctype="multipart/form-data"> <p> <input type="file" name="file"> <input type="submit" value="Upload"> </p> </form> </body> </html>
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。