不允许的方法 请求的 URL 不允许使用该方法。 (烧瓶)

时间:2021-04-30 18:31:54

标签: python flask flask-socketio

我在 Git 上克隆了一个 Flask 聊天应用 respo(链接:https://github.com/techwithtim/Chat-Web-App)。但是当我登录并尝试从表单发送消息时,服务器说 The method is not allowed for the requested URL.

我不确定因为数据库文件是分开的,但是我认为问题出在

@view.route("/")
@view.route("/home")
def home():
    """
    displays home page if logged in
    :return: None
    """
    if NAME_KEY not in session:
        return redirect(url_for("views.login"))

    return render_template("index.html", **{"session": session})

@view.route("/get_messages")
def get_messages():
    """
    :return: all messages stored in database
    """
    db = DataBase()
    msgs = db.get_all_messages(MSG_LIMIT)
    messages = remove_seconds_from_messages(msgs)

    return jsonify(messages)


并且发送消息是 index.html like

<div class="container">
    <div id="messages" class="overflow-auto msgs" style="overflow-y: scroll; height:500px;">
    </div>
    <form method="POST" id="msgForm" action="" style="bottom:0; margin: 0% 0% 0% 0%;">
        <div class="input-group mb-3">
              <input type="text" class="form-control" placeholder="Message" aria-label="Message" id="msg">
              <div class="input-group-append">
                <button class="btn btn-success" type="submit" id="sendBtn">Send</button>
              </div>
        </div>
    </form>
</div>

0 个答案:

没有答案