Код: Выделить всё
`async function makeReservation() {
const date = document.getElementById('date').value;
const time = document.getElementById('time').value;
const guests = document.getElementById('guests').value;
const response = await fetch('http://localhost:5000/reserve', {
method: 'POST',
headers: { 'Content-Type':'application/json' },
body: JSON.stringify({ date, time, guests })
});
const data = await response.json();
alert(data.message);
fetchReservations();`
< /code>
Файл, который обрабатывает кнопку книги из индекса, но на этапе отладки ошибка «Исключение произошла: Ссылкаерр: MakerErvation не определяется» < /p>
Это код app.py для бэкэнда < /p>
@app.route('/reserve', methods=['POST'])
@login_required
def reserve():
data = request.get_json()
new_reservation = Reservation(user_id=current_user.id, date=data['date'], time=data['time'], guests=data['guests'])
db.session.add(new_reservation)
db.session.commit()
return jsonify({'message': 'Prenotazione effettuata con successo!'}), 201
@app.route('/reservations', methods=['GET'])
@login_required
def get_reservations():
reservations = Reservation.query.filter_by(user_id=current_user.id).all()
return jsonify([{'id': r.id, 'date': r.date, 'time': r.time, 'guests': r.guests} for r in reservations])
https://github.com/pasquale19922/projectworkuni.git
Я попытался изменить код без какого -либо успеха
Подробнее здесь: https://stackoverflow.com/questions/794 ... with-flask