我的本地计算机上有一个 django 应用程序。我可以使用以下网址从浏览器访问该应用程序:http://localhost:8000/myapp/
但是我无法使用主机的IP访问该应用程序:http://193.140.209.49:8000/myapp/我收到404错误。
我该怎么办?有什么建议吗?
我假设您正在使用开发服务器。如果是这样,那么您需要专门绑定到您的外部 IP,以便服务器在那里可用。试试这个命令:
./manage.py runserver 193.140.209.49:8000
我也有类似的问题。就我而言,我必须执行以下操作:
python manage.py runserver 0.0.0.0:8000
http://localhost:8000
http://127.0.0.1:8000
http://192.168.0.99:8000
端口 8080 对我来说不起作用,所以我必须添加端口 8081。
在 Windows Defender 中添加端口 8081
在互联网路由器的虚拟服务器中添加端口 8081
python manage.py runserver 0.0.0.0:8081
http://103.122.xxx.xx:8081
设置.py
ALLOWED_HOSTS = ['127.0.0.1', 'localhost', '103.122.xxx.xx', '192.168.0.99']