我是 python 和 django 的新手。昨天我第一次执行了“python manage.py runserver”(就在 django-admin startproject 之后..),它显示在 http://127.0.0.1:8000/ 处启动开发服务器。 。但在 Chrome 中它说“无法访问此网站”。
搜索错误后,我意识到我必须在 settings.py 的 ALLOWED_HOST 列表(开头是一个空列表)中添加“127.0.0.1”。这解决了错误并显示了 django 祝贺页面。
但今天又出现同样的“无法访问此站点,127.0.0.1 拒绝连接”错误。
有人可以帮我解决这个问题吗?
This link has the project tree
编辑:我在安装 django 本身时也遇到了问题。在执行“pip install django”时出现类似 "pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available" and many other line of errors.
的错误在阅读堆栈溢出中的评论后,有人建议从 anaconda 提示符处进行 pip install,只有在那之后我才能安装 django。
最佳答案
这里的问题肯定与你的操作系统有关,也许你有另一个应用程序干扰了django服务器,最终你可以运行
python manage.py runserver 0.0.0.0:8000
并尝试从 http://your-IPv4 访问该项目地址:8000,不要忘记将允许主机的设置更改为 ['*'] 以接受所有地址。
尝试将此 View 添加到您的项目文件夹并将其指向“/”路径
View .py
from django.http import HttpResponse
def homepage(request):
return HttpResponse('hello world')
url.py
from . import views
urlpatterns = [
path('/', views.homepage)
]
关于python - django manage.py runserver后127.0.0.1拒绝连接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61922275/