使用 Flask 链接到网站中的另一个页面
Linking to another page within a website with Flask
我正在尝试制作一个网站,现在我只是想确保我可以让基本部分正常工作。
当我在应该将我重定向到我的测试页的索引页上单击 link 时,我收到 404 未找到错误。
我进行了大量搜索,试图弄清楚如何解决我的问题,但没有任何效果。一个看起来应该是我的问题的精确修复的问题是 ,但在尝试更改 test_link.html 中的 href 以匹配 flaskApp.py 中的路线后,我仍然收到错误消息] 或在 test_link.html 中尝试 url_for。我不确定还能尝试什么。
如有任何帮助,我们将不胜感激。
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>
您在 app.route("/test_link")
之前错过了 @
,并且您的路线没有注册。这就是为什么你有 404
我正在尝试制作一个网站,现在我只是想确保我可以让基本部分正常工作。
当我在应该将我重定向到我的测试页的索引页上单击 link 时,我收到 404 未找到错误。
我进行了大量搜索,试图弄清楚如何解决我的问题,但没有任何效果。一个看起来应该是我的问题的精确修复的问题是
如有任何帮助,我们将不胜感激。
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>
您在 app.route("/test_link")
之前错过了 @
,并且您的路线没有注册。这就是为什么你有 404