找不到Django -Page(404)请求方法:GET方法

时间:2020-04-14 13:07:54

标签: django python-3.x

我对Django非常陌生,我正在尝试运行一个URL,但是我没有找到此页面错误。我浏览了将近90%的帖子,但对我没有任何帮助。 这是三个.py文件

views.py .....

from django.shortcuts import render
from django.http import HttpResponse


def index(request):
   return HttpResponse('Hello world....')

** products \ urls.py ****

from django.urls import path
from . import views    #.means current folder ,we are importing a module


urlpatterns=[
    path(' ', views.index),
]

pyshop \ urls.py .......

from django.contrib import admin
from django.urls import path,include

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

我遇到了错误.....

Page not found (404)
Request Method: GET
Request URL:    http://127.0.0.1:8000/products/
Using the URLconf defined in pyshop.urls, Django tried these URL patterns, in this order:

admin/
products/
The current path, products/, didn't match any of these.

1 个答案:

答案 0 :(得分:0)

我认为您必须删除路径上的空格:

urlpatterns=[
    path(' ', views.index),
]

赞:

urlpatterns=[
    path('', views.index),
]