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.
I'm using django version 2.2.4 and i'm using regular expression on my home url pattern
My home app url
urls.py
from django.conf.urls import url
from . import views
urlpatterns = [
url(r'^$', views.home, name='home')
]
My home view
view.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
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. 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/
Simply change this to
path('', views.home)
It will work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.