【问题标题】:The current path, imageupload, didn't match any of these, Page not Found Django当前路径 imageupload 与其中任何一个都不匹配,Page not Found Django
【发布时间】:2021-01-27 07:34:58
【问题描述】:

我是 Django 新手,我正在尝试构建一个图像分类器应用程序,我刚刚尝试构建该应用程序,但出现此错误,我该如何解决?

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

imageupload ^$ [name='home']
admin/
The current path, imageupload, 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.

以下是我在应用中所做的所有更改: 这是 imgUpload 应用中的 views.py 文件

from django.shortcuts import render

# Create your views here.
def home(request):
    return render(request, 'home.html')

这是 imageUpload 应用中的 urls.py 文件

from django.contrib import admin
from django.urls import path,include
from . import views
urlpatterns = [
    path('^$', views.home, name ='home'),
]

这是 Imageclassifier 文件夹中的 urls.py:

"""imageclassifier URL Configuration

The `urlpatterns` list routes URLs to views. For more information please see:
    https://docs.djangoproject.com/en/3.1/topics/http/urls/
Examples:
Function views
    1. Add an import:  from my_app import views
    2. Add a URL to urlpatterns:  path('', views.home, name='home')
Class-based views
    1. Add an import:  from other_app.views import Home
    2. Add a URL to urlpatterns:  path('', Home.as_view(), name='home')
Including another URLconf
    1. Import the include() function: from django.urls import include, path
    2. Add a URL to urlpatterns:  path('blog/', include('blog.urls'))
"""

    from django.contrib import admin
    from django.urls import path,include
    
    urlpatterns = [
        path('imageupload', include('imgUpload.urls')),
        path('admin/', admin.site.urls),
        
    ]

另外,我在模板文件夹中添加了一个 home.html 文件。我该如何解决这个错误?

【问题讨论】:

    标签: python django django-models image-classification


    【解决方案1】:

    在最新的 django 路径方法中,您不需要在路径中使用 ^$。只需从路径中删除该 ^$ 即可。

    【讨论】:

    • 我应该把它留空吗?
    猜你喜欢
    • 1970-01-01
    • 2019-05-18
    • 2020-11-22
    • 1970-01-01
    • 2020-04-18
    • 2020-01-02
    • 1970-01-01
    • 2018-12-01
    相关资源
    最近更新 更多