【问题标题】:Cannot Access the Local Host on Python 127.0.0.1:8000 in browser无法在浏览器中访问 Python 127.0.0.1:8000 上的本地主机
【发布时间】:2022-12-14 12:46:50
【问题描述】:
from django.contrib import admin
from django.urls import path, include

urlpatterns = [
    path('admin/', admin.site.urls),
    path('products/'),include('products.urls') #this line
]

嗨,任何人。很抱歉问这种问题,但这是我第一次尝试 python。 path('products/'),include('products.urls') 怎么了? 如果我删除该行,我可以在我的教程解释添加该行以访问http://127.0.0.1:8000/ 以在浏览器中显示 Hello World,但如果我广告该行,我的结果是加载问题页。终端中显示此错误:

  File "C:\Users\BinarK\PycharmProjects\PyShop\pyshop\urls.py", line 23, in <module>
    path('products/'),include('products.urls')
TypeError: _path() missing 1 required positional argument: 'view'

enter image description here

【问题讨论】:

    标签: python browser path pycharm localhost


    【解决方案1】:

    我改成path('products/', include('products.urls')) 浏览器中的结果是:

    Page not found (404)
    Request Method:   GET
    Request URL:  http://127.0.0.1:8000/products
    

    使用 pyshop.urls 中定义的 URLconf,Django 按以下顺序尝试了这些 URL 模式:

    admin/
    

    当前路径,产品,与这些都不匹配。

    你看到这个错误是因为你的 Django 设置文件中有 DEBUG = True 。将其更改为 False,Django 将显示标准的 404 页面。

    但它仍然没有运行。

    我转到“设置”并将最后一行从Debug = True 更改为False,但没有任何改变,它仍然无法访问该 URL。

    我正在使用 Windows 11 和 Python 3.9。

    【讨论】:

      【解决方案2】:

      我遇到了一个非常相似的问题,我忘记在 urls.py 文件中添加以下导入

      from django.conf.urls import include
      

      试一试

      【讨论】:

        猜你喜欢
        • 2015-03-09
        • 2014-05-24
        • 1970-01-01
        • 2014-02-26
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2019-01-17
        • 2015-12-24
        相关资源
        最近更新 更多