Hi all,
When I use app engine to develop a simple website, uploading image
using html form, I met the following error:
[template is used in my application]
----------------------------------------------------------------------------------------------------------------------------------------------
Traceback (most recent call last):
File "/tools/google/google_appengine/google/appengine/ext/webapp/
__init__.py", line 507, in __call__
handler.get(*groups)
File "/mnt/hgfs/share/cloud/app/netcoc/netcoc.py", line 53, in get
self.response.out.write(template.render(template_file,
to_template_values))
File "/tools/google/google_appengine/google/appengine/ext/webapp/
template.py", line 80, in render
t = load(template_path, debug)
File "/tools/google/google_appengine/google/appengine/ext/webapp/
template.py", line 108, in load
template = django.template.loader.get_template(file_name)
File "/tools/google/google_appengine/lib/django/django/template/
loader.py", line 80, in get_template
template = get_template_from_string(source, origin, template_name)
File "/tools/google/google_appengine/lib/django/django/template/
loader.py", line 88, in get_template_from_string
return Template(source, origin, name)
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 158, in __init__
self.nodelist = compile_string(template_string, origin)
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 174, in compile_string
return parser.parse()
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 273, in parse
compiled_result = compile_func(self, token)
File "/tools/google/google_appengine/lib/django/django/template/
defaulttags.py", line 544, in do_for
nodelist_loop = parser.parse(('endfor',))
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 254, in parse
filter_expression = self.compile_filter(token.contents)
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 338, in compile_filter
return FilterExpression(token, self)
File "/tools/google/google_appengine/lib/django/django/template/
__init__.py", line 558, in __init__
raise TemplateSyntaxError, "Could not parse the remainder: %s" %
token[upto:]
TemplateSyntaxError: Could not parse the remainder: ()
----------------------------------------------------------------------------------------------------------------------------------------------
This is my Model:
----------------------------------------------------------------------------------------------------------------------------------------------
class MsgTable(db.Model):
user = db.UserProperty()
image = db.BlobProperty()
content = db.StringProperty(multiline=True)
date = db.DateTimeProperty(auto_now_add=True)
----------------------------------------------------------------------------------------------------------------------------------------------
This is the data sent to template
----------------------------------------------------------------------------------------------------------------------------------------------
to_template_values = {
'MsgRs': MsgRs,
'url': url,
'url_txt': url_txt,
}
template_file = os.path.join(os.path.dirname(__file__),
'index.htm')
self.response.out.write(template.render(template_file,
to_template_values))
----------------------------------------------------------------------------------------------------------------------------------------------
This is the final part: index.htm and Image app:
----------------------------------------------------------------------------------------------------------------------------------------------
<html>
<head>
<link type="text/css" rel="stylesheet" href="/css/main.css" />
</head>
<body>
{% for item in MsgRs %}
<img src="image?image_id={{ item.key() }}"></img>
{% if item.user %}
<b>{{ item.user.nickname }}</b> wrote:
{% else %}
An anonymous person wrote:
{% endif %}
<blockquote>{{ item.content|escape }}</blockquote>
{% endfor %}
<form action="/sign" method="post">
<div><textarea name="content" rows="3" cols="60"></textarea></div>
<div><input type="file" name="image"/></div>
<div><input type="submit" value="Sign Guestbook"></div>
</form>
<a href="{{ url }}">{{ url_txt }}</a>
</body>
</html>
----------------------------------------------------------------------------------------------------------------------------------------------
class Image (webapp.RequestHandler):
def get(self):
item = db.get(self.request.get("image_id"))
if item.image:
self.response.headers['Content-Type'] = "image/png"
self.response.out.write(item.image)
else:
self.response.out.write("No image")
----------------------------------------------------------------------------------------------------------------------------------------------
If I delete this line:
<img src="image?image_id={{ item.key() }}"></img>
It's ok, but once I use this line to show the image, error come out as
I just shown in above(first part of this mail)
Any help on this is definitely appreciated.
Shiqing
--
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.