1

http://127.0.0.1:8000/给出默认 url 时,应用程序能够获取默认页面,但是当我尝试使用这些页面连接时, http://127.0.0.1:8000/customer/ 我收到此错误作为回溯

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

admin/
The current path, customer/, didn’t match any of these.

You’re seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.

这是我的代码 crm/urls.py--->

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


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

]

现在accounts/urls.py--->

from django.urls import path
from . import views


urlpatterns = [
    path('', views.home,name="ShopHome"),
    path('products/', views.products,name="ProductsHome"),
    path('customer/', views.customer,name="customerHome"),
]

现在accounts/view.py--->

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



def home(request):
    return HttpResponse('home')

def products(request):
    return HttpResponse('products')

def customer(request):
    return HttpResponse('customer')

这是我在设置中安装的应用程序-->

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'accounts',
]

请帮帮我,我在这里被击中了 2 天

4

1 回答 1

0

urls您需要在没有前导的情况下指向accounts应用程序的:accounts/

urlpatterns = [
    path('admin/', admin.site.urls),
    #    ↓↓ empty string
    path('', include('accounts.urls')),
]

否则,您可以通过以下方式访问客户视图:

http://127.0.0.1:8000/accounts/customer/

但这可能不是您想要的。

于 2021-05-23T08:28:01.033 回答