首页 > 解决方案 > 如果它不是表单,则在烧瓶中获取按钮?

问题描述

嗨,我正在尝试将葡萄酒保存在数据库中,并且我在这里有物化卡。因此,用户不必登录即可搜索葡萄酒,但当他们这样做时,它们会显示不同的葡萄酒。我正在尝试从当用户单击添加按钮时显示的那个。我不知道该怎么做。谢谢你的帮助。

这是我所有葡萄酒的展示模板

<div class="row">
    {% for w in newList %}
    <div class="col s6 m4">
      <div style="height: 570px" class="card">
          <!-- <a href="{{ url_for('login') }}" class="btn-floating halfway-fab waves-effect waves-light teal"  style="float:right; margin: 15px"><i class="material-icons">add</i></a> -->
          <button class="btn-floating halfway-fab waves-effect waves-light teal" type="submit" name="action">
            <i class="material-icons right">add</i>
          </button>
        </div>
          <div class="card-content">
          <span style="color: black; font-size: 22px; font-weight:normal ; line-height: 1.1" class="card-title">{{ w['name'] }}</span>
          <p><i class="material-icons">location_on</i> {{ w['region'] }}
          </p>
          <p> <i class="material-icons">attach_money</i> {{ w['price'] }}</p>
        </div>
      </div>
    </div>
  {% endfor %}
</div>

路线

@app.route('/save/<string:id>',method=['GET','POST'])
@login_required
def save(id):
    if current_user.is_authenticated:


    # saveWine=UserChoice()

标签: javascripthtmlforms

解决方案


Without a form, you would need to add an onClick() action on that button and configure an ajax request to call the route.

Without ajax, you'll need to create a form.

Read this to learn how you can implement ajax requests.


推荐阅读