3

I am using gae with django. I have an project named MusicSite with following url mapping-

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),
)

There is an application MusicSite inside MusicFun with the following 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)

now whenever a upload a file using /start and click Submit i am taken to a blank page with the following url-

localhost:8000/_ah/upload/ahhnb29nbGUtYXBwLWVuZ2luZS1kamFuZ29yGwsSFV9fQmxvYlVwbG9hZFNlc3Npb25fXxgHDA

These random alphabets keep varying but the result is same. A blank page after every upload. Somebody please help.

The server responses are as below-

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 -

1 Answer 1

3

Your upload handler is returning a 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.

This is almost certainly because it's throwing an exception; you need to persuade Django to log the exception so that you can see what's going wrong. Alternately, catch it and log it yourself!

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.