【发布时间】:2021-08-20 20:10:38
【问题描述】:
我想从此 javascript 文件 (header.js) 返回 about.html 页面。我在一个javascript文件中写了我的标题。 header.js 将在每个 html 文件中扩展。当我单击一个按钮时,我希望它重定向到 about.html 页面或使用 url_for 的任何其他 html 页面。我只想弄清楚如何从 javascript 文件重定向。 这是我的文件结构
/folder
/index.py
/templates
/index.html
/about.html
/static
/css
/js
/lib
/comp
/header.js
我的 header.js
class Header extends HTMLElement {
constructor() {
super();
this.html = `
<header>
<div class="wrapper">
<div id="logo-wrapper">
<img class="logo" src="images/logo3.png" alt="Jebako Logo"/>
<p id='header-name'><a href='index.html'>Jebako</a></p>
</div>
<div id="menu-wrapper">
<p id="menu-icon" class="fas fa-bars"></p>
<ul>
<li><a href="{{ Flask.url_for('about') }}">About</a></li>
<li><a href="media.html">Listen Live <span class="live"></span></a></li>
这是我的 index.py
from flask import Flask, render_template, redirect, request, abort, url_for
app = Flask(__name__)
@app.route('/')
def index_page():
return render_template('index.html')
@app.route('/about/')
def about():
return render_template('about.html')
if __name__ == "__main__":
app.run(debug=True)
【问题讨论】:
标签: javascript python html flask url-for