【发布时间】:2017-08-06 02:17:58
【问题描述】:
我有一个具有以下结构的基本 Flask 应用程序:
from flask import Flask
from flask import render_template
app = Flask(__name__,template_folder='E:\Programming\Python Projects\Flask')
@app.route('/')
def index():
return render_template('hello.html')
@app.route('/route/')
def route1():
return render_template('route1.html')
app.run(debug = True,port = 8080,host = '0.0.0.0')
你好.html:
<!DOCTYPE html>
<html>
<head>
<title>Rendered!!</title>
</head>
<body>
<h1>
The template has been rendered!!!<br>
<a href="localhost:8080/route">Route No. 1</a>
</h1>
</body>
</html>
route1.html:
<!DOCTYPE html>
<html>
<head>
<title>Route No. 1</title>
</head>
<body>
<h2>
This is the first route!!!<br>
Hello World!!!
</h2>
<iframe src="https://www.youtube.com/embed/YQHsXMglC9A" width="853" height="480" frameborder="0" allowfullscreen></iframe>
</body>
</html>
当我打开 localhost:8080 时,它工作正常。
但是当我点击链接时,它说:
The address wasn’t understood
Firefox doesn’t know how to open this address, because one of the following protocols (localhost) isn’t associated with any program or is not allowed in this context.
当我在地址栏中手动输入地址localhost:8080/route 时,它工作正常。
此外,在新选项卡中打开时也可以正常工作。
我需要帮助!!!
谢谢!!!
【问题讨论】:
-
您可以尝试将链接更改为仅
/route使其相对而不是绝对吗?或者,您可以添加http://作为前缀,使链接http://localhost:8080/route。