python - Google App Engine and Django templates: why do these two cases differ? -


I am new to Python, and to help create a simple blog, Google App Engine I am using. I have the following test code:

  entries = db (Entry) .der ("- published"). Get () comments = db.action (comment) .order ("published") .get () self.response.out.write (template.render (templatePath + 'test.django.html', {'entries': entries , 'Comments': Comments,}))  

And it looks like a DJ ango template:

  {% "master.django.html" } Expanded {% block pagetitle%} test page {% endblock pagetitle%} {% block content%} {% for entries in entries} & lt; P & gt; & Lt; A href = "/ post / {{e.slug}} /" & gt; {{E.title | Part}} - {{E.published | Date: "js o \ f fy"}} & lt; / P & gt; In {% Endfor%} {comments in comment.all%} & lt; P & gt; {{C.authorname}} {{c.published | Date: "d / m / y h: i"}} & lt; / P & gt; {% Endfor%} {% endblock content}}  

When I look at this templated page in the browser, I get:

  type error : The 'entry' object is not repeated  

line {code> {% for entries}% {/ code> to {entries for entries in%}.% } > fixes this problem, which is great.

However, this little bit I do not understand; In another template (for the archive page), I give the same thing, a list of entry objects:

  entries = db. Sign (entry) .order ("- published") . Fetch (range = 100) self.response.out.write (template.reader (templatepath + 'archive.django.html', {'entries': entries,}))  

The template is as follows:

  {% "master.django.html"%} extension {% block pagetitle%} home page {% endblock pagetitle%} {% block content%} & lt ; Ul & gt; {% To enter entries} 
  • gt; & Lt; A href = "/ post / {{entry.slug}} /" & gt; {{Entry.title | Escape}} & lt; Span & gt; {{Entry.published
  • This code works fine, without changing entries to Entries All ; Actually if I so I did not get any output to change (no error, absolutely nothing).

    Can anyone explain why this is so happy?

    EDIT: I basically got past the wrong piece of query code for another example, which would probably make things easier for people to answer me ... now it changed.

    You want to use .fetch (), not ():

      entries = db.Query (entry). Order ("- published"). Fetch () Comments = db.action (comment) .dr ("published"). Fetch ()  

    get () returns only the first item that matches the query criteria, so rather than an iterative collection, you will get an example, and the entry object.

    I can not tell why the second edition works so it seems that it should not be so.


    Comments

    Popular posts from this blog

    oracle - The fastest way to check if some records in a database table? -

    php - multilevel menu with multilevel array -

    jQuery UI: Datepicker month format -