我使用来自dynamodb的数据预先填充表单。我将所有内容作为 render_template 语句的一部分传递:
return render_template('edit_ride_input.html',
rideDate=item.get('ride_date'),
rideLocation=item.get('ride_location'),
rideLevel=item.get('ride_level'),
rideCap=item.get('ride_cap'),
rideVis=item.get('ride_vis'),
rideRange=item.get('ride_range'),
rideReg=item.get('ride_reg'),
rideFuel=item.get('ride_fuel'),
rideLunch=item.get('ride_lunch'),
rideMeetLocation=item.get('ride_meet_location'),
rideMeetTime=item.get('ride_meet_time'),
rideUnloadTime=item.get('ride_unload_time'),
rideUnloadLocation=item.get('ride_unload_location'),
rideDescription=item.get('ride_description'))
然后我在每个表单元素上使用 value = 属性来预填充数据:
<div class="form-group ">
<label class="col-md-4 control-label" for="ride_date">*Date:</label>
<div class="col-md-4">
<input id="ride_date" name="ride_date" value={{rideDate}} type="text" placeholder="DD/MM/YYYY" class="form-control" required="" />
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="ride_location">*Location:</label>
<div class="col-md-4">
<h1>{{rideLocation}}
<input id="ride_location" name="ride_location" value= {{rideLocation}} type="text" placeholder="Where is the ride being held?" class="form-control input-md" required="">
</div>
问题是,在呈现表单时,它只显示从变量到第一个空格的数据。例如,如果我传入 rideLocation 且值为“ Nightcap国家公园”,则输入字段中显示的所有内容均为“ Nightcap ” 。我知道变量包含完整的字符串,因为当我直接在页面中将其呈现为 {{rideLocation}} 时,我看到“ Nightcap National Park ”
我做错了吗?
答案 0 :(得分:1)
输入东西真的让你思考,当我想到,有时我的大脑确实有效:)
我突然想到直接输入pre-populate值时,需要用引号括起来。我认为烧瓶变量没有什么不同,所以我尝试用引号将它们包装起来:
<div class="form-group ">
<label class="col-md-4 control-label" for="ride_date">*Date:</label>
<div class="col-md-4">
<input id="ride_date" name="ride_date" value="{{rideDate}}" type="text" placeholder="DD/MM/YYYY" class="form-control" required="" />
</div>
</div>
<!-- Text input-->
<div class="form-group">
<label class="col-md-4 control-label" for="ride_location">*Location:</label>
<div class="col-md-4">
<h1>{{rideLocation}}
<input id="ride_location" name="ride_location" value= "{{rideLocation}}" type="text" placeholder="Where is the ride being held?" class="form-control input-md" required="">
</div>
你知道什么,它有效!
希望将来可以帮助其他人。