【问题标题】:Why Django base URL can't be reached?为什么无法访问 Django 基本 URL?
【发布时间】:2021-10-27 13:33:09
【问题描述】:

部署后,我无法访问我的 django 应用程序的基本 URL。

无法到达基本网址:

www.example.com

这会一直运行直到超时。

可以到达:

www.example.com/home/

这是我在 settings.py 中允许的主机:

ALLOWED_HOSTS = ['example.com', 'example' 'https://example.com/', '127.0.0.1']

这是我在 myapp/urls.py 中的 url 模式:

从 .views 导入索引

urlpatterns = [ 路径('',索引,名称='索引'), path('home/', index, name="index"), ]

我尝试过调整网址格式,但没有成功。感谢您的帮助。

编辑:

根 urls.py:

urlpatterns = [ 路径('',包括('myapp.urls')), 路径('admin/',admin.site.urls), ] + 静态(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

【问题讨论】:

    标签: python django url


    【解决方案1】:

    将允许的主机更改为

    ALLOWED_HOSTS = ['example.com', 'www.example.com', '127.0.0.1']
    

    【讨论】:

    • 嗯..这种格式不走运。我可能还缺少什么?
    • 你能分享你的根urls.py文件吗?
    • 添加在上面。我在此链接中尝试了一些解决方案,但无济于事。 stackoverflow.com/questions/7580220/…
    • 需要在 URLconf 中添加 '/home/' 路径
    猜你喜欢
    • 2015-09-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-07-09
    • 2021-09-21
    • 1970-01-01
    • 1970-01-01
    • 2015-01-11
    相关资源
    最近更新 更多