【发布时间】:2021-03-07 05:43:45
【问题描述】:
我正在使用 Jinja 模板实现一个烧瓶应用程序,并且我正在尝试根据用户当前所在的 URL 一次向我的导航锚元素之一添加一个活动类。但是,这仅在我加载主页或刷新任何页面时有效,但在我单击其他页面时无效。
我尝试了许多使用纯 JavaScript、jQuery 和 jinja 模板的方法来解决这个问题,但所有这些方法都产生了我提到的相同结果。
这是我的 application.py 文件
@app.route("/")
def index():
return render_template("index.html", page="")
@app.route("/AboutUs")
def about():
return render_template("about.html")
@app.route("/Services")
def services():
return render_template("services.html")
这是我的布局 html 模板中导航菜单的代码:
<div class="navbar-nav mx-auto" id="menu">
<a {% if request.path == '/' %}class="active nav-link"{% endif %}
class="nav-link" href="/">Home</a>
<a {% if request.path == '/AboutUs' %}class="active nav-link"{% endif %}
class="nav-link" href="/AboutUs">About Us</a>
<a {% if request.path == '/Services' %}class="active nav-link"{% endif %}
class="nav-link" href="/Services">Our Services</a>
</div>
谁能告诉我问题出在哪里?
【问题讨论】:
标签: javascript jquery flask jinja2