我有一个基本的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')
hello.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
。 - abagshaw