Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I insert this python code into my html template?
    text
    copied!<p>the python for the get method:</p> <pre><code> posts = Post.all().order('num') for post in posts: key = post.key() self.write('&lt;div class = "art"&gt;&lt;img src="img?img_id=%s" class = "art" width = "500"&gt;&lt;/img&gt;&lt;/div&gt;' % post.key()) self.render("art.html", posts = posts) </code></pre> <p>art.html:</p> <pre><code>{% extends "base.html" %} {% block content %} &lt;form method="post" class = "art"&gt; {% for post in posts %} &lt;div class = "art_title"&gt;{{post.title}}&lt;/div&gt; &lt;div class = "art_note"&gt;{{post.note}}&lt;/div&gt; &lt;br&gt; {% endfor %} &lt;/form&gt; &lt;/div&gt; {% endblock %} </code></pre> <p>This works fine for displaying a single post, but when there are more than one posts, all the art is rendered at the top in one giant heap and then the title and description notes are rendered in another heap of words. I want the page to render the art, title, and note together, for a single post.</p> <p>How would I insert the python for loop with the string substitution into the html? (I also tried inserting the html into the python but the extends "base.html" line messes it up...if I were to do it this way, how would I extend the "base.html"?)</p> <p>EDIT:</p> <p>I tried </p> <pre><code>posts = Post.all().order('num') self.render("art.html", posts = posts) </code></pre> <p>and </p> <pre><code>&lt;div class = "art_box"&gt; &lt;form method="post" class = "art"&gt; {% for post in posts %} &lt;div class="art"&gt;&lt;img src="img?img_id={{post.key}}" class="art" width="500"&gt;&lt;/img&gt;&lt;/div&gt; &lt;div class = "art_title"&gt;{{post.title}}&lt;/div&gt; &lt;div class = "art_note"&gt;{{post.note}}&lt;/div&gt; &lt;br&gt; {% endfor %} &lt;/form&gt; &lt;/div&gt; </code></pre> <p>which didn't display the pictures at all, only the title and the description.</p> <p>Is there a way I can get the value of post.key in the html and substitute that in the url?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload