首页 > 解决方案 > 为什么瓶子模板引擎会截断表单字段中的渲染文本?

问题描述

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

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

编辑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 ¯\_(ツ)_/¯ -->

标签: bottletemplating

解决方案


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

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

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

推荐阅读