【问题标题】:Flask form pre-population only displays up to first whitepace [duplicate]烧瓶形式预填充仅显示第一个空格[重复]
【发布时间】:2018-01-07 21:22:11
【问题描述】:

我正在使用来自 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>

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

我做错了吗?

【问题讨论】:

    标签: python html forms flask render


    【解决方案1】:

    打字真的会让你思考,当我思考的时候,有时我的大脑真的在工作:)

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

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

    你知道吗,它奏效了!

    希望这对将来的其他人有所帮助。

    【讨论】:

    • 这是基本要求的
    猜你喜欢
    • 2017-08-03
    • 1970-01-01
    • 2021-06-28
    • 2020-05-07
    • 2021-05-05
    • 2020-10-10
    • 1970-01-01
    • 2018-08-07
    • 2018-10-11
    相关资源
    最近更新 更多