【发布时间】:2020-08-17 11:05:25
【问题描述】:
我有一个将日期设置为按钮的 html 表格日历。当用户单击该按钮时,该按钮会将他们重定向到约会页面。但是,我需要将按钮的值(设置为相应日期)传递到约会页面,以便用户可以在该日期预订会议。
<button type="button" value = "1" onclick="window.location.href='{{ url_for( 'appointments') }}';">1</button>
我想在单击按钮时将值“1”传递给 /appointments 页面,但我不知道该怎么做。是否有可能做到这一点?我在烧瓶 python 上这样做。
约会.html
{% extends 'base.html' %}
{% block body %}
<div class="container">
<form method="POST" action="/appointments">
<h2>Appointments</h2>
<p>
{{ form.start.label }}<br>
{{ form.start }}
</p>
<p>
{{ form.end.label }}<br>
{{ form.end }}
</p>
<p>
{{ form.description.label }}<br>
{{ form.description }}
</p>
<p>
{{ form.guestName.label }}<br>
{{ form.guestName }}
</p>
<input type="submit">
<!-- <button class = "btn btn btn-primary btn block" type="submit">Set up</button> -->
</form>
</div> <!-- /container -->
{% endblock %}
预约路线:
@app.route('/appointments', methods=['GET', 'POST'])
def appointments():
form = AddAppointment()
if form.is_submitted():
startingTime = datetime.datetime.strptime(
form.start.data, '%H:%M').time()
endingTime = datetime.datetime.strptime(form.end.data, '%H:%M').time()
print(startingTime, endingTime)
appt = Appointments(starttime=form.start.data, endtime=form.end.data,
description=form.description.data, guestName=form.guestName.data)
print(appt)
db.session.add(appt)
db.session.commit()
return redirect('/dashboard')
return render_template('appoitments.html', form=form)
【问题讨论】:
-
我们需要更多信息来帮助您。检查How to create a Minimal, Reproducible Example
-
刚刚添加了更多信息以使其更清晰