我正在尝试使用Flask上传文件。 这是我的HTML代码
<!DOCTYPE html>
<html>
<head>
<title>Python Starter Application</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" href="stylesheets/style.css" />
</head>
<body>
<form action="/upload">
File input
<input type="file" name="InputFile">
<button type="submit" class="btn btn-default">Upload</button>
</form>
</body>
</html>
这是我的烧瓶代码
import os
from flask import Flask, request
import swiftclient
try:
from SimpleHTTPServer import SimpleHTTPRequestHandler as Handler
from SocketServer import TCPServer as Server
except ImportError:
from http.server import SimpleHTTPRequestHandler as Handler
from http.server import HTTPServer as Server
app = Flask(__name__)
# Read port selected by the cloud for our application
PORT = int(os.getenv('PORT', 8000))
# Change current directory to avoid exposure of control files
os.chdir('static')
httpd = Server(("", PORT), Handler)
# connections
auth_url = ##
project = ##
projectId = ##
region = ##
userId = ##
username = ##
password = ##
domainId = ##
domainName = ##
container_name = ##
conn = swiftclient.Connection(key=password,
authurl=auth_url,
auth_version='3',
os_options={"project_id": projectId,
"user_id": userId,
"region_name": region})
@app.route('/upload', methods=['GET', 'POST'])
def upload_file():
file = request.files['InputFile']
file_name = file.filename
conn.put_object(container_name,
file_name,
contents=file_name.read(),
content_length=1024)
return '''
<html>
<title>Upload new File</title>
<body>
<h1>Successful</h1>
</body>
</html>
'''
try:
print("Start serving at port %i" % PORT)
httpd.serve_forever()
except KeyboardInterrupt:
pass
httpd.server_close()
我错过了什么吗? 我还是得到了
错误响应错误代码404.消息:找不到文件。错误代码说明:404 = Nothing与给定的URI匹配。
答案 0 :(得分:-1)
就像你正在使用烧瓶我认为最好的解决方案是烧瓶解决方案,如:
lineNo | Comment | updatedDate | UpdateBy
-----------------------------------------------------------
1 | Comment line 1 | 23-May-16 | Abhi
2 | Comment line 2 | 23-May-16 | Abhi
3 | Comment line 3 | 23-May-16 | Rohit
4 | Comment line 4 | 23-May-16 | Malay
5 | Comment line 5 | 23-May-16 | Malay
6 | Comment line 6 | 23-May-16 | Abhi
7 | Comment line 7 | 23-May-16 | Abhi
8 | Comment line 8 | 23-May-16 | Abhi
9 | Comment line 4 | 23-May-16 | Abhi