Reputation: 3
I am getting this error
Request Method: GET Using the URLconf defined in Webwork.urls, Django tried these URL patterns, in this order:
admin/ ^ ^department/$ ^ ^department/([0-9]+)$ ^ ^employee/$ ^ ^employee/([0-9]+)$
The empty path didn’t match any of these.
here is my code:
from django.contrib import admin
from django.urls import path
from django.conf.urls import url,include
urlpatterns = [
path('admin/', admin.site.urls),
url(r'^',include('EmpApp.urls'))
]
and
from django.conf.urls import url
from EmpApp import views
urlpatterns=[
url(r'^department/$',views.departmentApi),
url(r'^department/([0-9]+)$',views.departmentApi),
url(r'^employee/$',views.employeeApi),
url(r'^employee/([0-9]+)$',views.employeeApi),
]
Can anyone please help me solve this error?
Upvotes: 0
Views: 831
Reputation: 11
you didn't have any error it's you didn't have created any page for http://127.0.0.1:8000 this path
use path instead of url as i shown in my code
from django.contrib import admin
from django.urls import path
from django.conf.urls import include
urlpatterns = [
path('',include('app.urls')),
path('admin/', admin.site.urls),
]
and
from django.urls import path
from app import views
urlpatterns=[
path('',views.index), # added this line
path('departments',views.departmentApi),
path('departments/<slug:id>',views.departmentApi)
]
and add code to EmpAppapp\views.py file
def index(request):
return render(request, './index.html')
now create index.html File in EmpAppapp\templates\index.html and write anything you want to display on the http://127.0.0.1:8000/ page
<h1>hello</h1>
if you get ImportError: cannot import name 'url' from 'django.conf.urls' this error than refer this page ImportError: cannot import name 'url' from 'django.conf.urls' after upgrading to Django 4.0
Upvotes: 1