Search code examples
bottletemplating

Why is bottle templating engine is truncating rendered text in a form field?


Sometimes I can not wrap my head around bootstrap. I am trying to pass a value to an Html template using bottle.py (python 3), and when using bootstrap the data passed gets truncated before rendering and I do not understand what is happening.

edit : I can see the entire string when looking at the page source, it is only visually when looking at the value rendered to the browser.

edit 2 : after removing boostrap and doing the same thing in pure html, the issue is still there, it seems like the usage of {{get('title','')}} will only display "Chief" if "Chief Operating Officer" is stored under title, however when looking at the source code the entire value is there. I do not know how to make bottle render the entire value.

Here is the code

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




and the html template

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

Solution

  • Well apparently everything inside the html value tag is expected to be surrounded with quotes.

    So the correct way of writing the html input block is :

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