简体   繁体   English

Google App Engine Python HTML表格

[英]Google App Engine Python HTML Table

I am trying to create a table within a Google App Engine Application where the background color in a table changes periodically based on input. 我正在尝试在Google App Engine应用程序中创建表格,表格中的背景颜色会根据输入定期更改。 Does anyone know how to accomplish this? 有谁知道如何做到这一点? Here is my code: 这是我的代码:

    self.response.out.write("""
         <img src="/images/resistor.png" width = "150">
         <table border = "1">
         <tr height="150" >
         <td bgcolor="%s" width="35">  </td> <td bgcolor="%s" width="35">  </td> <td bgcolor="%s" width="35">  </td> <td bgcolor="%s" width="35"> </td> %(Red,Blue,Black,Green)
         </tr>
         </table>
          <form action="/sign" method="post">
            <div><textarea name="content" rows="3" cols="60"></textarea></div>
            <div><input type="submit" value="Sign Guestbook"></div>
          </form> """)
    self.response.out.write('</pre></body></html>')

For example the Red,Green... Colors in %( ) will be variables that will change so at one point they all may be Red or Blue and Yellow. 例如,%()中的Red,Green ...颜色将是会更改的变量,因此在某一时刻它们可能都是Red或Blue和Yellow。

That type of string-formatting is deprecated . 该类型的字符串格式已被弃用 Please use the .format() method in new code. 请在新代码中使用.format()方法。 Example: 例:

self.response.out.write("""
     <img src="/images/resistor.png" width = "150">
     <table border = "1">
       <tr height="150" >
         <td bgcolor="{}" width="35">  </td> 
         <td bgcolor="{}" width="35">  </td> 
         <td bgcolor="{}" width="35">  </td> 
         <td bgcolor="{}" width="35">  </td>
       </tr>
     </table>
     <form action="/sign" method="post">
       <div><textarea name="content" rows="3" cols="60"></textarea></div>
       <div><input type="submit" value="Sign Guestbook"></div>
     </form> """.format( ('Red','Blue','Black','Green') ))
self.response.out.write('</pre></body></html>')

And for anything beyond the basic have a look at using templates. 对于基本以外的任何内容,请查看使用模板。 Examples of templating systems are Jinja2 and Django Templates. 模板系统的示例是Jinja2和Django模板。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM