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?

Received: by 10.58.254.39 with SMTP id af7mr3241682ved.41.1349535363058;
        Sat, 06 Oct 2012 07:56:03 -0700 (PDT)
X-BeenThere: python-tornado@googlegroups.com
Received: by 10.220.147.138 with SMTP id l10ls3789695vcv.7.gmail; Sat, 06 Oct
 2012 07:56:00 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.52.91.168 with SMTP id cf8mr2124394vdb.6.1349535360925; Sat,
 06 Oct 2012 07:56:00 -0700 (PDT)
Authentication-Results: ls.google.com; spf=pass (google.com: domain of
 alabdeloua...@gmail.com designates internal as permitted sender)
 smtp.mail=alabdeloua...@gmail.com; dkim=pass
 header...@gmail.com
Received: by g18g2000vbf.googlegroups.com with HTTP; Sat, 6 Oct 2012 07:56:00
 -0700 (PDT)
Date: Sat, 6 Oct 2012 07:56:00 -0700 (PDT)
In-Reply-To: <CAPVnKEkpP0jZOmFQgU=jO4hmFgTQUP9C-gxq+3-Lu2FKqg8iqw@mail.gmail.com>
References: <04ba4173-8dd9-4780-abb2-58ba91bbafe6@q4g2000vbg.googlegroups.com> <CAPVnKEkpP0jZOmFQgU=jO4hmFgTQUP9C-gxq+3-Lu2FKqg8iqw@mail.gmail.com>
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (Windows NT 5.1) AppleWebKit/537.4 (KHTML, like
 Gecko) Chrome/22.0.1229.79 Safari/537.4,gzip(gfe)
Message-ID: <070dac33-7c74-4f6a-b0db-187eb53305e9@g18g2000vbf.googlegroups.com>
Subject: Re: catch exceptions in templates?
From: aliane abdelouahab <alabdeloua...@gmail.com>
To: Tornado Web Server <python-tornado@googlegroups.com>
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable

sadly this dident work, the solution is to delete both product, from
uploader and user's cart.

On 5 oct, 22:26, Russ Weeks <rwe...@newbrightidea.com> wrote:
> Hi, Aliane,
>
> Move the 'try' into the 'for' loop:
>
> {% for produit in produits %}
> {% try %}
> [...]
>
> Or, move the 'except' out of the 'for' loop. =A0(This will compile but th=
e
> behaviour will not quite be how you want)
> -Russ
>
> On Fri, Oct 5, 2012 at 10:58 AM, aliane abdelouahab <alabdeloua...@gmail.=
com
>
>
>
>
>
>
>
> > wrote:
> > 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):
> > =A0 =A0 @tornado.web.authenticated
> > =A0 =A0 def get(self):
> > =A0 =A0 =A0 =A0 user =3D self.get_secure_cookie("mechtari")
> > =A0 =A0 =A0 =A0 info =3D tornado.escape.json_decode(user)
> > =A0 =A0 =A0 =A0 email =3D info["personnel"]["email"]
> > =A0 =A0 =A0 =A0 try:
> > =A0 =A0 =A0 =A0 =A0 =A0 produits =3D self.db.users.find({"personnel.ema=
il":email},
> > {"produit_down":1, "_id":0}).distinct("produit_down")
> > =A0 =A0 =A0 =A0 =A0 =A0 renderer =3D self.fs
> > =A0 =A0 =A0 =A0 =A0 =A0 error =3D gridfs.NoFile
> > =A0 =A0 =A0 =A0 except (errors.AutoReconnect, errors.ConnectionFailure)=
:
> > =A0 =A0 =A0 =A0 =A0 =A0 =A0 =A0 self.redirect("/error")
> > =A0 =A0 =A0 =A0 self.render("achats.html", produits=3Dproduits,
> > renderer=3Drenderer, error=3Derror)
>
> > {% if produits=3D=3D[] %}
> > 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):
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\web.py", line 1064, in _execute
> > =A0 =A0 =A0 =A0 getattr(self, self.request.method.lower())(*args, **kwa=
rgs)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\web.py", line 1846, in wrapper
> > =A0 =A0 =A0 =A0 return method(self, *args, **kwargs)
> > =A0 =A0 =A0 File "G:\Mon projet\sog-emouk\handlers.py", line 486, in ge=
t
> > =A0 =A0 =A0 =A0 self.render("achats.html", produits=3Dproduits,
> > renderer=3Drenderer, error=3Derror)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\web.py", line 515, in render
> > =A0 =A0 =A0 =A0 html =3D self.render_string(template_name, **kwargs)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\web.py", line 619, in render_string
> > =A0 =A0 =A0 =A0 t =3D loader.load(template_name)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 326, in load
> > =A0 =A0 =A0 =A0 self.templates[name] =3D self._create_template(name)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 358, in _create_template
> > =A0 =A0 =A0 =A0 template =3D Template(f.read(), name=3Dname, loader=3Ds=
elf)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 220, in __init__
> > =A0 =A0 =A0 =A0 self.file =3D _File(self, _parse(reader, self))
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 831, in _parse
> > =A0 =A0 =A0 =A0 block_body =3D _parse(reader, template, operator, in_lo=
op)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 831, in _parse
> > =A0 =A0 =A0 =A0 block_body =3D _parse(reader, template, operator, in_lo=
op)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 825, in _parse
> > =A0 =A0 =A0 =A0 block_body =3D _parse(reader, template, operator, opera=
tor)
> > =A0 =A0 =A0 File "C:\Python27\lib\site-packages\tornado-2.4.post1-py2.7=
.egg
> > \tornado\template.py", line 777, in _parse
> > =A0 =A0 =A0 =A0 raise ParseError("%s block cannot be attached to %s blo=
ck" %
> > (operator, in_block))
> > =A0 =A0 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=3D=3D[] %}
> > ..
> > {% 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!