2010-10-02 80 views
1

我不知道爲什麼我無法上傳我的文件?當我點擊提交而不是重定向到默認頁面(即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() 
+1

那麼,你的HTML確實表示將表單提交給'/ sign' – 0xff0000 2012-09-26 18:51:16

回答

1

你爲什麼表單數據發送到一個不存在的頁面?

嘗試改變HTML到:

<form action="/" enctype="multipart/form-data" method="post"> 
... 

...因爲 「/」 是你的表單處理代碼所在。

+0

woot!解決了我的問題。儘管如此,仍然需要檢查上傳部分。有沒有快速的方法來做到這一點? – Khoi 2010-10-02 05:33:32

+1

檢查管理控制檯中上傳是否成功完成。 – bernie 2010-10-02 05:35:14

+0

該死的快!非常感謝。 – Khoi 2010-10-02 05:37:18

相關問題