簡體   English   中英

在Django urls.py文件中獲取“空路徑與這些中的任何一個都不匹配”錯誤

[英]Getting “The empty path didn't match any of these” error in Django urls.py file

項目結構

我正在研究Django,我在運行這樣的代碼時遇到錯誤:

Using the URLconf defined in mysite.urls, Django tried these URL

patterns, in this order:  

^admin/  
^employees/  

The empty path didn't match any of these.

這是我的urls.py:

from django.conf.urls import url
from django.contrib import admin
from webapp import views
from django.urls import path
from rest_framework.urlpatterns import format_suffix_patterns


urlpatterns = [

url(r'^admin/', admin.site.urls),
url(r'^employees/', views.employeeList.as_view()),
]

這是vies.py:

class employeeList(APIView):

def get(self, request):
    employees1 = employees.objects.all()
    serializer = employeesSerializer(employees1, many=True)

    return Response(serializer.data)

def post(self):
    pass

和Settings.py:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'rest_framework',
'webapp'
 ]

嘗試更改網址

url(r'^employees/', views.employeeList.as_view())

url(r'^employees/$', views.employeeList.as_view(), name='employees' )

暫無
暫無

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

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