【发布时间】:2019-10-09 12:01:01
【问题描述】:
我正在处理一个烧瓶项目,并遇到方法未找到错误。我只是想在按下提交按钮时从我的主页转到我的游戏页面。我不知道我哪里出错了。
我知道这个问题已经被问过好几次了,但我已经尝试了这些问题中的所有方法,但仍然出现错误。
这是我的路线文件:
from flask import render_template
from app import app
from app.forms import LoginForm
@app.route('/')
@app.route('/homepage', methods=['GET', 'POST'])
def homepage():
form = LoginForm()
if form.validate_on_submit():
return redirect(url_for('index'))
return render_template('homepage.html', title='Welcome', form=form)
@app.route('/index')
def index():
return render_template('index.html')
这是我在主页上包含按钮的 html 代码:
<html>
<head>
{% if title %}
<title>{{ title }} - CatanAI</title>
{% else %}
<title>CatanAI</title>
{% endif %}
</head>
<h1>Welcome to Settlers of Catan AI</h1>
<body>
<form method="post" action='{{url_for('index')}}'>
<p>{{ form.submit() }}</p>
</form>
</body>
</html>
这是我试图路由到的代码的 html:
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Catan</title>
<script src="{{ url_for('static', filename="css/main.css")}}"></script>
</head>
<body>
<canvas id="canvas" ></canvas>
<script src="{{ url_for('static', filename="js/board.js")}}"></script>
<script src="{{ url_for('static', filename="js/game.js")}}"></script>
<script src="{{ url_for('static', filename="js/location.js")}}"></script>
<script src="{{ url_for('static', filename="js/main.js")}}"></script>
<script src="{{ url_for('static', filename="js/player.js")}}"></script>
</body>
</html>
当我按下按钮时,我得到了不允许的 405 方法。感谢您的帮助。
【问题讨论】:
标签: python html flask http-status-code-405