It gives me error 405 “Method not allowed”. Only method ‘Get’ works. Here is my cod:
I deliberately made mistakes here:
@app.route('/books/<int: #book_id>/
Because new members can only have two links in their topic.
‘’’
from flask import Flask, request, render_template, jsonify
app = Flask(name)
app.config[“JSON_AS_ASCII”] = False
@app.route(‘/books/’, methods=[‘GET’])
def read_books():
return jsonify({“content”: “Получаем все книжки”})
@app.route(‘/books/<int: #book_id>/’, methods=[‘GET’])
def read_book(book_id):
return jsonify({“content”: f"Получаем книжку {book_id}"})
@app.route(‘/books/’, methods=[‘POST’])
def create_book():
return jsonify({“content”: “Создаем книжку”})
@app.route(‘/books/<int #:book_id>/’, methods=[‘PUT’])
def update_book(book_id):
return jsonify({“content”: f"Обновляем книжку {book_id}"})
@app.route(‘/books/<int #:book_id>/’, methods=[‘DELETE’])
def delete_book(book_id):
return jsonify({“content”: f"Удаляем книжку {book_id}"})
if name == ‘main’:
from waitress import serve
serve(app, host=‘0.0.0.0’, port=5050)
‘’’