【问题标题】:Can't access ip 0.0.0.0 and ip 127.0.0.1无法访问 ip 0.0.0.0 和 ip 127.0.0.1
【发布时间】: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 使用的默认端口 - 50008000
  • 我不确定,但是当其他程序已经使用此端口时,您可以获得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")

标签: python flask


【解决方案1】:

理想情况下,0.0.0.0 表示本地计算机上的所有 IPV4 地址。但有时它不会(尤其是在 Windows 机器中)。

如果你正在尝试启动服务器并访问本地尝试

app.run(host="127.0.0.1", port=80)

【讨论】:

  • 感谢您的意见。我试过了,但出现以下错误:我需要考虑笔记本电脑设置或 Wi-Fi 是否有问题。 127.0.0.1 - - [21/May/2021 22:37:13] “GET / HTTP/1.1” 404 - 127.0.0.1 - - [21/May/2021 22:37:14] “GET /favicon.ico HTTP /1.1" 404 -
猜你喜欢
  • 2020-03-29
  • 2015-06-04
  • 2020-10-04
  • 2017-06-30
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-12-29
  • 1970-01-01
相关资源
最近更新 更多