【问题标题】:Using bootstrap with web.py's form使用带有 web.py 表单的引导程序
【发布时间】:2013-07-23 11:32:09
【问题描述】:

我在我的支持中使用 web.py 来生成一个表单。我也想使用引导表单类。这是我的 html 中的 sn-p

  <form name="test" method="POST"> 
  $:form.render()
  <input type="submit" name="button" value="Login" />
  </form>

当由 web.py 生成时,变成

<form name="login" method="POST" class = "register"> 
<table>
    <tr><th><label for="username">Username:</label></th><td><input type="text" id="username" name="username"/></td></tr>
    <tr><th><label for="password">Password:</label></th><td><input type="password" id="password" name="password"/></td></tr>
    <tr><th><label for="password_again">Repeat your password:</label></th><td><input type="password" id="password_again" name="password_again"/></td></tr>
</table>
<input type="submit" value="Register" />
</form>

但是。这使得在我的代码中添加引导功能变得很困难。 直接来自引导网站的一个示例是:

<form>
  <fieldset>
    <legend>Legend</legend>
    <label>Label name</label>
    <input type="text" placeholder="Type something…">
    <span class="help-block">Example block-level help text here.</span>
    <label class="checkbox">
      <input type="checkbox"> Check me out
    </label>
    <button type="submit" class="btn">Submit</button>
  </fieldset>
</form>

是否可以将这些类型的功能添加到我的表单中?

【问题讨论】:

    标签: html forms web.py


    【解决方案1】:

    请改用$:form.render_css()

    【讨论】:

      【解决方案2】:

      我编写了继承自 Form 类的类,并修改了 render_css 方法。看起来是这样的:

      class bootstrap_form(form.Form):
      def render_bootstrap(self):
          from web import net
          out = []
          out.append(self.rendernote(self.note))
          for i in self.inputs:
              out.append('<div class="form-group">')
              if not i.is_hidden():
                  out.append('<label for="%s">%s</label>' % (i.id, net.websafe(i.description)))
              out.append(i.pre)
              out.append(i.render())
              out.append(self.rendernote(i.note))
              out.append(i.post)
              out.append('</div>')
              out.append('\n')
          return ''.join(out) 
      

      我希望你会发现这很有用。

      【讨论】:

        猜你喜欢
        • 2014-01-03
        • 2016-08-28
        • 1970-01-01
        • 1970-01-01
        • 2012-02-22
        • 1970-01-01
        • 2018-09-19
        • 2015-10-19
        • 1970-01-01
        相关资源
        最近更新 更多