【问题标题】:Why is bottle templating engine is truncating rendered text in a form field?为什么瓶子模板引擎会截断表单字段中的渲染文本?
【发布时间】:2021-06-18 21:33:35
【问题描述】:

有时我无法将我的头绕在引导程序上。我正在尝试使用bottle.py(python 3)将值传递给Html模板,并且在使用引导程序时,传递的数据在渲染之前被截断,我不明白发生了什么。

edit : 在查看页面源代码时,我可以看到整个字符串,只有在查看呈现给浏览器的值时才能看到。

编辑2:删除boostrap并在纯html中做同样的事情后,问题仍然存在,似乎{{get('title','')}} 的用法只会在“首席运营官”存储在标题下时显示“首席”,但是,当查看源代码时,整个值就在那里。我不知道如何让瓶子呈现整个价值。

这里是代码

#python3

from bottle import request, template, route, run




@route('/')
def new():
    data = {'name':'This will be truncated :(  '}
    return template('new.tpl', **data)

if __name__ == "__main__":
    run(host='localhost', port=8080)




和html模板

   <head>
   <link rel="stylesheet"      href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous">

   </head>
 <! -- This works start -->
   <form>
     <label for="fname">this works : {{get('name','')}} </label>
     <br>
     <input type = "submit" value="Submit">
   </form>
 <! -- This works stop -->

 <! -- The following does not work  -->
<div class="col-sm-3">
   <class="col-xs-4 control-label">This does not</label>
   <input required type="text" class="form-control" value= {{get('name','')}}>
</div>

 <! -- and I do not know why ¯\_(ツ)_/¯ -->

【问题讨论】:

  • 是在视觉上被截断还是字段内的实际值包含的符号少于提供的符号?
  • 你说得对,我从来没有想过要看看页面源代码。确实这个领域应有尽有,它似乎只是视觉上的。
  • 那么它应该是输入元素上的一些填充

标签: bottle templating


【解决方案1】:

显然,html value 标记内的所有内容都应该用引号括起来。

所以html输入块的正确写法是:

<input required type="text" class="form-control" value= '{{get('name','')' }}>

【讨论】:

    猜你喜欢
    • 2012-10-28
    • 1970-01-01
    • 2016-08-23
    • 1970-01-01
    • 2020-04-25
    • 1970-01-01
    • 2015-10-29
    • 2011-05-31
    • 2013-01-10
    相关资源
    最近更新 更多