我有这样的代码,用于将用户重定向到Python flask中的不同子页面:
@app.route('/')
def main():
return render_template('interface.html')
@app.route('/#ordergrade/')
def ordergrade():
return sort.orderbygrade(True, False).to_html()
字符串interface.html
的代码如下:
<!DOCTYPE html>
<html>
<head>
<title>xxxxxxxxxxxxxx</title>
</head>
<body>
<h1>Options</h1>
<p>Click on the buttons below to be redirected to a web page.</p>
<button onclick="window.location.hash='#ordergrade/'">1</button>
<button onclick="window.location.hash='#orderuniversity/'">2</button>
<button onclick="window.location.hash='#showopts/'">3</button>
<button onclick="window.location.hash='#delete/'">4</button>
<button onclick="window.location.hash='#infnum/'">5</button>
<button onclick="window.location.hash='#supnum/'">6</button>
</body>
</html>
型
当点击第一个按钮时,我被正确地重定向到/#ordergrade
页面,但只有interface.html
被渲染。为什么会发生这种情况?
一切似乎都很顺利,除了什么也没发生。
1条答案
按热度按时间vvppvyoh1#
URL的
fragment
(#
之后的部分)不会发送到服务器,因此当您访问路径/#ordergrade/
时,服务器只能看到/
。如果你想在URL中使用
#
,你需要使用URL encoding进行编码,例如,字符串
也可以在客户端处理,看看浏览器/JavaScript
hashchange
事件,或者考虑使用包含路由解决方案的前端javascript框架。