2010-03-28 120 views
3

我正在使用gae和django。 我有一個名爲MusicSite的項目有以下網址mapping-使用Django在Google應用程序引擎中上傳文件

urls.py 

from django.conf.urls.defaults import * 
from MusicSite.views import MainHandler 
from MusicSite.views import UploadHandler 
from MusicSite.views import ServeHandler 

urlpatterns = patterns('',(r'^start/', MainHandler), 
     (r'^upload/', UploadHandler), 
     (r'^/serve/([^/]+)?', ServeHandler), 
) 

裏面有MusicFun應用MusicSite具有以下 codes-

views.py 

import os 
import urllib 

from google.appengine.ext import blobstore 
from google.appengine.ext import webapp 
from google.appengine.ext.webapp import blobstore_handlers 
from google.appengine.ext.webapp import template 
from google.appengine.ext.webapp.util import run_wsgi_app 

def MainHandler(request): 
    response=HttpResponse() 
    upload_url = blobstore.create_upload_url('http://localhost: 
8000/upload/') 
    response.write('<html><body>') 
    response.write('<form action="%s" method="POST" 
enctype="multipart/form-data">' % upload_url) 
    response.write("""Upload File: <input type="file" 
name="file"><br> <input type="submit" 
     name="submit" value="Submit"> </form></body></html>""") 
    return HttpResponse(response) 

def UploadHandler(request): 
    upload_files=request.FILES['file'] 
    blob_info = upload_files[0] 
    response.redirect('http://localhost:8000/serve/%s' % 
blob_info.key()) 

class ServeHandler(blobstore_handlers.BlobstoreDownloadHandler): 
def get(self, resource): 
    resource = str(urllib.unquote(resource)) 
    blob_info = blobstore.BlobInfo.get(resource) 
    self.send_blob(blob_info) 

現在只要上傳使用文件/啓動和 點擊提交我帶到以下url的空白頁面 -

localhost:8000/_ah/upload/ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgHDA 

這些rando m字母保持不變,但結果相同。每次上傳後都有空白頁 。 有人請幫忙。

服務器的響應是因爲如下─

INFO:root:"GET /start/ HTTP/1.1" 200 - 
INFO:root:"GET /favicon.ico HTTP/1.1" 404 - 
INFO:root:Internal redirection to http://localhost:8000/upload/ 
INFO:root:Upload handler returned 500 
ERROR:root:Invalid upload handler response. Only 301, 302 and 303 
statuses are permitted and it may not have a content body. 
INFO:root:"POST /_ah/upload/ 
ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgCDA 
HTTP/1.1" 500 - 
INFO:root:"GET /favicon.ico HTTP/1.1" 404 - 

回答

3

您的上傳處理程序返回一個500:

INFO:root:Upload handler returned 500 
ERROR:root:Invalid upload handler response. Only 301, 302 and 303 statuses are permitted and it may not have a content body. 

這是幾乎可以肯定,因爲它是拋出一個異常;你需要說服Django記錄這個異常,以便你可以看到發生了什麼問題。或者,抓住它並自己登錄!

相關問題