在flask localhost服务器中使用javascript位置对象时出现问题

在flask localhost服务器中使用javascript位置对象时出现问题,javascript,Javascript,我正在用python中的flask构建一个本地主机网站。我创建了一个html页面,并尝试使用javascript链接它们。具体来说,我使用的是window.location对象。我试过每一种组合,但似乎都不管用。它不断追加url地址,而不是替换。例如,当我点击链接时,它会转到 0.0.0.0:5000/0.0.0:5000/家,而不仅仅是0.0.0.0:5000/家 python代码片段 from flask import Flask, render_template, redi

我正在用python中的flask构建一个本地主机网站。我创建了一个html页面,并尝试使用javascript链接它们。具体来说,我使用的是window.location对象。我试过每一种组合,但似乎都不管用。它不断追加url地址,而不是替换。例如,当我点击链接时,它会转到 0.0.0.0:5000/0.0.0:5000/家,而不仅仅是0.0.0.0:5000/家

python代码片段

        from flask import Flask, render_template, redirect, url_for
    from rpi_rf import RFDevice
    from transmitterPrimetest import send_code
    
    app = Flask(__name__)
    
    
    @app.route("/")
    def main():
        return render_template("index.html")
    
    @app.route("/home")
    def home():
        return render_template("index.html")
        
    @app.route("/usersettings")
    def settings():
        return render_template("usersettings.html")
    
    @app.route("/pricehistory")
    def price():
        return render_template("pricehistory.html")

Snippet of JavaScript Code
function showHome(){
    window.location.href = "/"
return 
}
function showUsersettings(){
    window.location.href = "/usersettings";
    return
}

function  showPricehistory(){
    window.location.href = "/pricehistory";
    return
}

Snippet HTML code

    li id="navHome" class="nav-link active"><a href="#" onclick="return showHome()" value="Display">Home</a></li>
                        <li id="navSettings" class="nav-link"><a href="#" onclick="return showUsersettings()" value= "Display">User Settings</a></li>
                        <li id="navPricing" class="nav-link"><a href="#" onclick="return showPricing()">Price History</a></li>
            
从flask导入flask,呈现模板,重定向,url
从rpi_rf导入射频设备
从transmitterPrimetest导入发送代码
app=烧瓶(名称)
@附件路线(“/”)
def main():
返回渲染模板(“index.html”)
@应用程序路径(“/主页”)
def home():
返回渲染模板(“index.html”)
@app.route(“/usersettings”)
def设置():
返回呈现模板(“usersettings.html”)
@app.route(“/pricehistory”)
def price():
返回呈现模板(“pricehistory.html”)
JavaScript代码片段
函数showHome(){
window.location.href=“/”
返回
}
函数showUsersettings(){
window.location.href=“/usersettings”;
返回
}
函数showPricehistory(){
window.location.href=“/pricehistory”;
返回
}
HTML代码片段
li id=“导航主页”class=“导航链接激活”>