Flask窗体预填充仅显示到第一个白色

2024-05-15 02:26:16 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在使用来自dynamodb的数据预填充一个表单。我将所有内容作为呈现模板语句的一部分传入:

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>

问题是,在呈现表单时,它只显示从变量到第一个空格的数据。例如,如果我传入值为“Nightcap National Park”的rideLocation,则输入字段中显示的所有内容都是“Nightcap”。我知道变量包含完整的字符串,因为当我在页面中直接将其呈现为{{rideLocation}}时,我看到了“夜总会国家公园”

我做错什么了吗


Tags: 数据divforminputgetdatecollocation
1条回答
网友
1楼 · 发布于 2024-05-15 02:26:16

把东西打出来真的会让你思考,当我思考的时候,有时我的大脑真的在工作:)

我突然想到,当直接输入预填充值时,它们需要用引号括起来。我认为flask变量不会有什么不同,所以我也尝试用引号将它们括起来:

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

你知道吗,成功了

希望这能在将来帮助别人

相关问题 更多 >

    热门问题