aliane abdelouahab
unread,Oct 5, 2012, 1:58:05 PM10/5/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Tornado Web Server
hi, i get errors when trying to catch exceptions:
ParseError: except block cannot be attached to for block
what i try to do, is to detect if a product in a user cart has been
deleted by detecting the image in gridfs because i've duplicated the
information of this product to make it fast for the database.
here is what i did:
class AchatsHandler(BaseHandler):
@tornado.web.authenticated
def get(self):
user = self.get_secure_cookie("mechtari")
info = tornado.escape.json_decode(user)
email = info["personnel"]["email"]
try:
produits = self.db.users.find({"personnel.email":email},
{"produit_down":1, "_id":0}).distinct("produit_down")
renderer = self.fs
error = gridfs.NoFile
except (errors.AutoReconnect, errors.ConnectionFailure):
self.redirect("/error")
self.render("achats.html", produits=produits,
renderer=renderer, error=error)
{% if produits==[] %}
there is no products
{% else %}
{% try %}
{% for produit in produits %}
information about the produt
{% except error %}
this product dont exist
{% end %}
{% end %}
{% end %}
and the error:
Traceback (most recent call last):
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 1064, in _execute
getattr(self, self.request.method.lower())(*args, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 1846, in wrapper
return method(self, *args, **kwargs)
File "G:\Mon projet\sog-emouk\handlers.py", line 486, in get
self.render("achats.html", produits=produits,
renderer=renderer, error=error)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 515, in render
html = self.render_string(template_name, **kwargs)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\web.py", line 619, in render_string
t = loader.load(template_name)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 326, in load
self.templates[name] = self._create_template(name)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 358, in _create_template
template = Template(f.read(), name=name, loader=self)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 220, in __init__
self.file = _File(self, _parse(reader, self))
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 831, in _parse
block_body = _parse(reader, template, operator, in_loop)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 831, in _parse
block_body = _parse(reader, template, operator, in_loop)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 825, in _parse
block_body = _parse(reader, template, operator, operator)
File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7.egg
\tornado\template.py", line 777, in _parse
raise ParseError("%s block cannot be attached to %s block" %
(operator, in_block))
ParseError: except block cannot be attached to for block
[E 121005 18:14:19 web:1485] 500 GET /achats (::1) 12.00ms
but if i do this:
{% try %}
{% if produits==[] %}
..
{% else %}
{% for produit in produits %}
..
{% end %}
{% end %}
{% except error %}
<h2>No file!</h2>
{% end %}
i dont get the result i want; dot get "no file!" and the product is
shown!