简体   繁体   English

当前路径 home/ 与其中任何一个都不匹配

[英]The current path, home/, didn't match any of these

I have two apps on my project- one is accounts and home home app url - http://localhost:8000/home/ is rising an error that the current path, home/, didn't match any of these.我的项目中有两个应用程序 - 一个是帐户和家庭主页应用程序 url - http://localhost:8000/home/正在引发一个错误,即当前路径 home/ 与其中任何一个都不匹配。

I'm using django version 2.2.4 and i'm using regular expression on my home url pattern我使用的是 django 2.2.4 版,我在我的主页 url 模式上使用正则表达式

My home app url我的家庭应用网址

urls.py网址.py

from django.conf.urls import url
from . import views

urlpatterns = [
    url(r'^$', views.home, name='home')
]

My home view我的家视图

view.py查看.py

from django.shortcuts import render
from django.http import HttpResponse
# Create your views here.

def home(request):
    return HttpResponse('It worked !..')

Main url主网址

urls.py网址.py

urlpatterns = [

    path(r'^admin/', admin.site.urls),
    url(r'^$', views.login_redirect, name='login_redirect'),  # automatically takes to login page
    path(r'^account/', include(('accounts.urls','accounts'), namespace='accounts')),
    path(r'^home/', include(('home.urls','home'), namespace='home')),
    path('', include('django.contrib.auth.urls')),

] 

i'm expecting simple message on the browser that is 'It worked!..'我期待浏览器上的简单消息是“它有效!...”

If you are using django 2.2.4 then, there is no need for using regular expression in URL pattern.如果您使用的是 django 2.2.4,则无需在 URL 模式中使用正则表达式。 change改变

path(r'^home/', include(('home.urls','home'), namespace='home'))

to

path('home/', include('home.urls'))

Similarly, change同样,改变

url(r'^$', views.home, name='home')

to

path('', views.home,  name = 'home')

For further info on URL dispatcher check https://docs.djangoproject.com/en/2.2/topics/http/urls/有关 URL 调度程序的更多信息,请查看https://docs.djangoproject.com/en/2.2/topics/http/urls/

Simply change this to只需将其更改为

path('', views.home)

It will work.它会起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM