@si20004

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

FLASKの画面遷移がおかしい

解決したいこと

aws環境でのFLASKの画面遷移について

クラウド9でFLASKの画面遷移を試してみようと思い書いてみたのですが、設定した遷移先のURL:~/resultに移動すると以下のようなメッセージが表示されました。

Not Found
The requested URL was not found on the server. If you entered the URL manually please check your spelling and try again.

参照したサイトのように遷移先のURLについても何か設定が必要なのでしょうか。
もしよろしければ回答よろしくお願いします。

参照したサイト

ファイル構成

myapp
│└─app.py
│
└─templates
  └─app.html

app.py

from flask import Flask, request, render_template
import os
import calendar
app = Flask(__name__)


@app.route('/')
def hello():
    return render_template("app.html")

if __name__ == "__main__":
    app.run(host = '0.0.0.0', port = 50000)
    app.debug = True

@app.route("/result", methods=["POST"])
def result():
    return render_template("app.html")

app.html

<html lang="ja">
<head>
    <meta charset=utf-8>
<body>
    <h3>適当なフォーム</h3>

    <form action="/result"  method="post">
        <p> <input type="text" name="a"> </p>
        <p> <input type="text" name="b"> </p>
        <p> <input type="text" name="c"> </p>
        <p> <textarea rows=5 cols=50 name="d"></textarea> </p>
        <p> <input type="submit" value="テスト"> </p>
    </form>
    <p>{{b}}</p>
</body>
</html>
0 likes

1Answer

URLを直接叩いた場合はGETになりますので、/resultのmethodsがPOSTに限定されていることが原因ではないでしょうか。

methods=["GET"]に変更するか、helloの方と同様にメソッドを指定しない(この場合デフォルトでGETになるはず)ことで
改善される気がします。

0Like

Your answer might help someone💌