【发布时间】:2021-05-20 22:33:38
【问题描述】:
代码没有问题,但是不行。
更改端口号或关闭防火墙时也是如此。
如果有问题,我很抱歉,因为这个问题是由翻译写的。
我已经在网上尝试了很多方法。
# file name : index.py
# pwd : /project_name/app/main/index.py
from flask import Blueprint, request, render_template, flash, redirect, url_for
from flask import current_app as app
main= Blueprint('main', __name__, url_prefix='/')
@main.route('/main', methods=['GET'])
def index():
return render_template('/main/index.html')
# file name : __init__.py
# pwd : /project_name/app/__init__.py
from flask import Flask
app= Flask(__name__)
from app.main.index import main as main
app.register_blueprint(main)
<!--file name : index.html-->
<!--pwd : /project_name/app/templates/main/index.html-->
<html>
<head>
This is Main page Head
</head>
<body>
This is Main Page Body
</body>
</html>
# file name : run.py
# pwd : /project_name/run.py
from app import app
app.run(host="0.0.0.0", port=80)
* Serving Flask app "app" (lazy loading)
* Environment: production
WARNING: This is a development server. Do not use it in a production deployment.
Use a production WSGI server instead.
* Debug mode: off
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit)
/error code/
http://0.0.0.0:80/ access > ERR_ADDRESS_INVALID
或
127.0.0.1 - - [21/May/2021 06:41:30] "GET /show HTTP/1.1" 404 -
【问题讨论】:
-
错误显示获取
/show的问题,因为您的代码中没有.route('/show'。 -
您尝试了哪些端口?系统可能会阻止某些端口。特别是低于 1024 的端口。通常代码使用 Flask 使用的默认端口 -
5000或8000 -
我不确定,但是当其他程序已经使用此端口时,您可以获得
ERR_ADDRESS_INVALID。 -
感谢您的评论。但是 .route('/show') 也不起作用。我也用过80、8000、8080、5000的端口,但是一直没有解决。这个很难(硬。 (TT)
-
检查它是否适用于
127.0.0.1。如果有效,那么0.0.0.0的问题与 Flask 无关,而仅与系统有关,它可能需要在不同的地方搜索解决方案 - 即。 Network Engineering 或者 SuperUser。顺便说一句,您可以使用route("/")而不是route("/main")