使用Flas链接到网站内的其他页面

2024-04-25 10:29:57 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在努力做一个网站,现在我只是想确保我能得到基本的部分工作。你知道吗

当我单击索引页上的链接,该链接应该将我重定向到测试页时,我得到一个404notfound错误。你知道吗

我做了一系列的搜索,试图找出如何解决我的问题,但没有任何工作。有一个问题看起来应该是404 Error when trying to link to another page flask对我的问题的一个确切的解决办法,但是在尝试在test中更改我的href之后,我仍然得到了我的错误_链接.html来匹配我的路线烧瓶app.py或者在测试中尝试_链接.html. 我不知道还能尝试什么。你知道吗

任何帮助都将不胜感激。你知道吗

你知道吗烧瓶app.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)

你知道吗索引.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>

试验_链接.html你知道吗

<!DOCTYPE html>

<html lang="en">

<head>
    <title>hello</title>
</head>

<body>
    test link
</body>

Tags: totestappflask烧瓶title链接html