Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
Message from discussion catch exceptions in templates?
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
aliane abdelouahab  
View profile  
 More options Oct 5 2012, 1:58 pm
From: aliane abdelouahab <alabdeloua...@gmail.com>
Date: Fri, 5 Oct 2012 10:58:05 -0700 (PDT)
Local: Fri, Oct 5 2012 1:58 pm
Subject: catch exceptions in templates?
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!


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.