我不知道爲什麼我無法上傳我的文件?當我點擊提交而不是重定向到默認頁面(即http://localhost:8082)時,它重定向到http://localhost:8082/sign。我沒有建立這樣的路徑,所以它返回鏈接斷開。這裏是我的html:無法在Google App Engine中上傳文件
<form action="/sign" enctype="multipart/form-data" method="post">
<div><label>Excel file submit:</label></div>
<div><input type="file" name="excel"/></div>
<div><input type="submit" value="Upload file"></div>
</form>
我的app.yaml:
application: engineapp01
version: 1
runtime: python
api_version: 1
handlers:
- url: /js
static_dir: js
- url: /css
static_dir: css
- url: .*
script: main.py
main.py:
import os;
from google.appengine.ext import webapp
from google.appengine.ext.webapp import util
from google.appengine.ext.webapp import template
from google.appengine.ext import db
from mmap import mmap,ACCESS_READ
from xlrd import open_workbook
class Account(db.Model):
name = db.StringProperty()
type = db.StringProperty()
no = db.IntegerProperty()
co = db.IntegerProperty()
class MyFile(db.Model):
filedata = db.BlobProperty()
class MainHandler(webapp.RequestHandler):
def get(self):
#delete all old temporary entries
query = Account.all()
results = query.fetch(limit=40)
db.delete(results)
#temporary entry
acc = Account(name='temporaryAccountName',
type='temporaryType',
no=0,
co=500)
acc.put()
temp = os.path.join(os.path.dirname(__file__),'templates/index.htm')
tableData = ''
query = Account.all()
query.order('name')
results = query.fetch(limit=20)
for account in results:
tempStr= """
<tr>
<td align='left' valign='top'>%s</td>
<td align='left' valign='top'>%s</td>
<td align='left' valign='top'>%d</td>
<td align='left' valign='top'>%d</td>
</tr>""" % (account.name,account.type,account.no,account.co)
tableData = tableData + tempStr
outstr = template.render(
temp,
{'tabledata':tableData})
self.response.out.write(outstr)
def post(self):
myFile = MyFile()
excel = self.request.get("excel")
myFile.fileData = db.Blob(excel)
myFile.put()
self.redirect('/')
def main():
application = webapp.WSGIApplication([('/', MainHandler)],
debug=True)
util.run_wsgi_app(application)
if __name__ == '__main__':
main()
那麼,你的HTML確實表示將表單提交給'/ sign' – 0xff0000 2012-09-26 18:51:16