簡體   English   中英

當前路徑 imageupload 與這些都不匹配,Page not Found Django

[英]The current path, imageupload, didn't match any of these, Page not Found Django

我是 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 文件。 我該如何解決這個錯誤?

在最新的 django 路徑方法中,您不需要在路徑中使用 ^$。 只需從您的路徑中刪除 ^$ 即可正常工作。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM