【发布时间】:2020-02-23 08:40:04
【问题描述】:
我正在尝试制作一个网站,而现在我只是想确保我可以让基本部分正常工作。
当我单击索引页上应将我重定向到测试页的链接时,我收到 404 Not Found 错误。
我进行了大量搜索,试图找出如何解决我的问题,但没有任何效果。一个看起来应该是我的问题的确切解决方法的问题是404 Error when trying to link to another page flask,但在尝试更改我在 test_link.html 中的 href 以匹配我在 flaskApp.py 中的路线或尝试在 test_link 中尝试 url_for 后,我仍然收到错误消息.html。我不确定还能尝试什么。
任何帮助将不胜感激。
flaskApp.py
from flask import Flask, jsonify, redirect, render_template, request,
url_for
# Configure application
app = Flask(__name__)
@app.route("/")
def get_index():
return render_template('index.html')
app.route("/test_link")
def test_link():
return render_template('test_link.html')
if __name__ == "__main__":
app.run(debug=True)
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
</head>
<body>
<h1>Index Page</h1>
<p>
This is a test <a href="test_link">link</a>
</p>
</body>
</html>
test_link.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>hello</title>
</head>
<body>
test link
</body>
【问题讨论】:
标签: python html flask http-status-code-404