@Kurtis Rader
i'm sure the non-buildin type 'article' instance have 'title' attribute.The
'article' is dict like, so I always use article[0].title instead.
after format 'article[0]', information shown as below:
---
<!--Article(key=Key('Article', 5905064635924480),
title=u'mytitlestring tag', type=u'Translate')-->
---(use ' instead)
<!--Article(key=Key('Article', 5905064635924480), title=u'mysomestring',
type=u'Translate')-->
---
if i'm sure article[0] contains title property, as:article[0].title print
out 'mysomestring'.
For the non-buildin type, how to alert article[0].title in javascript?
@Markus Unterwaditzer
Did you say that I must use json to dumping the non-buildin type for jinja2?
if it is, I must redirect my focus to json way.
( but i think jinja2 could process alert("{{article[0].title}}"); in some
other way. )
2014-03-24 23:25 GMT+08:00 Kurtis Rader <[email protected]>:
> The expansion of {{article.title}} is done by the jinja2 template engine
> on the server before the javascript is executed on the client (i.e., the
> browser). So the fact you're using javascript to display the value is not
> relevant. Either GAE is affecting jinja2 behavior or your "article" object
> doesn't have a "title" attribute or member (if it's a dict like object) or
> the value isn't what you expect. Try embedding the following in your
> document:
>
> <!--
> {{'%r'|format(article)}}
> -->
>
>
> That will embed a python representation of the "article" object as a
> comment in the document. Then use your brower "view page source" command to
> see what was embedded. For example, I did this for one of my objects and
> got this:
>
> <!--
> {'last_changed_rfc3339': '2014-03-24T15:04:01Z',
> 'last_changed_rfc822': 'Mon, 24 Mar 2014 15:04:01 GMT',
> ...
> -->
>
>
> Note that the ' is a single-quote, which if you make the substitution
> yields the more familiar:
>
> {'last_changed_rfc3339': '2014-03-24T15:04:01Z',
> 'last_changed_rfc822': 'Mon, 24 Mar 2014 15:04:01 GMT',
>
>
>
>
>
> On Mon, Mar 24, 2014 at 7:31 AM, alex <[email protected]> wrote:
>
>> Hi guys,
>>
>> What i want like below:
>> ---
>> <script type="text/javascript">
>> alert({{article.title}});
>> </script>
>> ---
>> this code block was writen in some.html using jinja2 template, working by
>> GAE.
>> it alert nothing, empty content on dialog.
>> if I take the code below instead,it work fine:(but need pass extra
>> variable article.title as "title")
>> ---
>> <script type="text/javascript">
>> alert({{title}});
>> </script>
>> ---
>>
>> so 1. ,jinja/jinja2 could only pass int, bool, and so on(these regular
>> type), isn't it?
>> 2. if I want pass the instance "article", do I must dump it by json?
>> 3. Is any other way for code like article.title that passing to
>> javascript?
>> (some times i think this problem may be less relate with javascript.)
>>
>> thx,
>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "pocoo-libs" group.
>> To unsubscribe from this group and stop receiving emails from it, send an
>> email to [email protected].
>>
>> To post to this group, send email to [email protected].
>> Visit this group at http://groups.google.com/group/pocoo-libs.
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
>
> --
> Kurtis Rader
> Caretaker of the exceptional canines Junior and Hank
>
> --
> You received this message because you are subscribed to a topic in the
> Google Groups "pocoo-libs" group.
> To unsubscribe from this topic, visit
> https://groups.google.com/d/topic/pocoo-libs/Hfu3r1ZOWuw/unsubscribe.
> To unsubscribe from this group and all its topics, send an email to
> [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/pocoo-libs.
> For more options, visit https://groups.google.com/d/optout.
>
--
Zarey C.Y. Chang
--
You received this message because you are subscribed to the Google Groups
"pocoo-libs" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pocoo-libs.
For more options, visit https://groups.google.com/d/optout.