无法在浏览器中访问Python 127.0.0.1:8000上的本地主机

问题描述 投票:0回答:3
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/中运行本地主机,以添加该行来访问http://127.0.0.1:8000/products以显示浏览器中的“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
3个回答
0
投票

我把它改为

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。


0
投票

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

from django.conf.urls import include

尝试一下


0
投票

我绝对无法通过代理。

© www.soinside.com 2019 - 2024. All rights reserved.