python - django manage.py runserver后127.0.0.1拒绝连接

标签 python django networking ip

我是 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 urls.py code

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/

相关文章:

python - NLTK CoreNLPDependencyParser : Failed to establish connection

python - 是否可以使用 Django ORM 选择不接收仅接收基于实际列计算的值的表字段?

通过全局公共(public) IP 地址连接的 Python 套接字

python - Django:为什么当我在 django 中通过 popen 使用 Ghostscript 时,会出现 "file not found"错误

python - AES 在 python 中加密 在 php 中解密

python - Django 每月/每季度对 DateField() 数据进行分组

python - 如何在 Windows 7 上使用 Python 计算网络使用情况?

android - 将 Retrofit 与 RoboSpice 一起使用是否有意义?

python - 验证 ModelForm 时出现问题

Django/Ajax 发送 'none' 值查看