I can upload images to the Blobstore without any problems, but I've
had trouble retrieving and rendering them in my html template. I'm
using django-nonrel on appengine. I've tried to adapt django coding to
appengine, but being new to this I haven't had any success. My
relevant code is below. When I try to access the rendered broken
image's url I get the following error:
http://mackapp103.appspot.com/success/AMIfv94I_EVL2zU1gxCq7fqIr60veQfXulUagDaJnaGGdeupm5ioV6D8OzBKzcSiSIcDjd70et_6JE8wImOWYDzBm6Ua8sNfzink9bx6RqRUrtQPj9qnRA5kfGN4bKsboFsc3Cuk0-M2OsMWmMlccXIN9h9AMxrOAg/
Exception Type: BadKeyError
Exception Value:
Invalid string key
AMIfv94I_EVL2zU1gxCq7fqIr60veQfXulUagDaJnaGGdeupm5ioV6D8OzBKzcSiSIcDjd70et_6JE8wImOWYDzBm6Ua8sNfzink9bx6RqRUrtQPj9qnRA5kfGN4bKsboFsc3Cuk0-
M2OsMWmMlccXIN9h9AMxrOAg==.
Any thoughts on how to fix this would be appreciated very much.
Thanks!
models.py
class sports_photoitem(db.Model):
name = db.StringProperty()
photo = blobstore.BlobReferenceProperty()
def __unicode__(self):
return self.get_absolute_url()
@permalink
def get_absolute_url(self):
return ('upload_photo_view', [self.key()])
views.py
def download_file(request, object_id):
from codecs import encode
object_id=encode(object_id, 'utf-8')
files = sports_photoitem()
file=files.get(object_id)
return HttpResponse(file.photo.key(), content_type='image/
jpeg')
urls.py
url(r'^upload_photo/(?P<object_id>.+)/$',
'sports.views.download_file',
name="upload_photo_view"),
upload_photo.html
{% extends "base.html" %}
{% block content %}
<p><a href="/accounts/logout/">Logout</a></p>
<h1>Upload Photo</h1>
{% if upload_error %}
<div class="error">{{ upload_error }}</div>
{% endif %}
<form action="{{ upload_url }}" method="post"
enctype="multipart/form-data">
<ul>
{{ form.as_ul }}
<li><input type="file" name="photo"/></li>
<li><input type="submit"/></li>
</ul>
</form>
{% if oneimage %}
{% for one in oneimage %}
<p><img src="{{one.photo.key}}" alt="didnt
work" /></p>
{% endfor %}
{% endif %}
{% endblock %}
--
You received this message because you are subscribed to the Google Groups
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine?hl=en.