我尝试上传这2个错误,“ str没有保存”和keyerror:“文件”

时间:2019-09-15 05:59:58

标签: html flask

我正在尝试使用按钮将文件从前端上传到后端,但出现2个错误。

HTML内容:

 <!DOCTYPE html>

 <head>
   <title></title>
   <script>
   </script>
   <title>ritik</title>
 </head>

 <body>
   <form action="myform" enctype="mu_tipart/form-data" method="POST">
     <input type="file" name="fileupload" value="fileupload" id="fileupload">
     <label for="fileupload"> select file</label>
     <input type="submit" value="submit">
   </form>
   <input type=>
 </body>

这是我的烧瓶代码

from flask import Flask,render_template,request,url_for
import os
from werkzeug.utils import secure_filename
import networkx as nx
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
app=Flask(__name__, template_folder='template') 

@app.route("/myform",methods=['GET','POST'])
def myform():
    if request.method=='POST':
        f=request.form.get('key', 'file')
## here iam getting the second error ##
        f.save(secure_filename(f.filename))
        fname = secure_filename(file.filename)
## here iam trying to save it ##
        file.save('static/'+fname)
        #return "upload successfully"
        return render_template('image1.html')

@app.route("/")

def home():
    return render_template('image1.html')

if __name__=="__main__":
    with app.app_context():
        app.run(debug=True,use_reloader=False)

0 个答案:

没有答案