Django 的“python manage.py runserver”没有创建我可以访问的本地网站

问题描述

我正在尝试学习此在线课程,但在访问 django 制作的本地网站时遇到了困难。我遵循的教程是由 freecodecamp 编写的,我在尝试访问输出站点 http://127.0.0.1:8000/ 时遇到了 11 分钟标记。我正在关注 Jupyter Notebook 浏览器版本的本教程。

教程:https://www.freecodecamp.org/news/create-an-e-commerce-site-with-django-and-vue/

'python manage.py runserver' 行运行,我得到以下输出

System check identified no issues (0 silenced).
April 16,2021 - 03:37:04
Django version 3.2,using settings 'djacket_django.settings'
Starting development server at http://127.0.0.1:8000/
Quit the server with CONTROL-C.

当我将服务器地址复制并粘贴到浏览器中时,我收到以下错误消息,指出我无法连接到该站点

 Unable to connect
 Firefox can’t establish a connection to the server at 127.0.0.1:8000.

我真正发现解决这个问题的唯一资源是以下帖子,但是当我浏览我的 netstat 列表时,没有列出 :8000 的 IP,所以我认为我还没有用完那个地址。

发布: Django manage.py runserver is not working

解决方法

听起来您正在使用 WSL2,但尚未发现 WSL2 虚拟机的 IP 地址与 Windows IP 地址不同。 Windows 对 localhost 可能有自己的想法!

TL;DR:Use GWSL to run WSL2 apps on X Windows。这将允许您通过 X Windows 从 WSL2 运行浏览器,而无需担心。