python - Google App Engine Python HTML 表

标签 python html html-table

我正在尝试在 Google App Engine 应用程序中创建一个表格,其中表格中的背景颜色根据输入定期更改。有谁知道如何做到这一点? 这是我的代码:

    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>')

例如,%( ) 中的红色、绿色...颜色将是会发生变化的变量,因此在某一时刻它们都可能是红色或蓝色和黄色。

最佳答案

That type of string-formatting is deprecated 。请在新代码中使用 .format() 方法。示例:

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>')

对于基本内容之外的任何内容,请查看使用模板。模板系统的示例有 Jinja2 和 Django 模板。

关于python - Google App Engine Python HTML 表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15397522/

相关文章:

javascript - 在固定定位的 div 上隐藏/显示 Jquery 的问题

javascript - 从逗号分隔的字符串javascript创建html表

javascript - 将 TD 列转换为 TR 行

mysql的PHP表错误

python - 为什么使用按钮运行脚本时会打开 quote> 提示

python - 如何从 pyspark 数据帧更快地保存 csv 文件?

javascript - 如何从 JSON 解析 HTML 数据并将其呈现在 UIWebView 中(使用 Swift 3.0)

html - 如何在 HTML 中使一个部分适合 100% 的视口(viewport)

python - Django应用无法识别.env文件,我尝试通过os,Django-environ和dotenv对其进行设置,但没有任何效果

python - 使用 Python 多处理进行通信时 OSX 和 Linux 之间的性能差异