Django urls.py文件中出现“空路径与任何这些都不匹配”错误

时间:2019-06-24 11:21:52

标签: python django django-rest-framework

Project structure

我正在使用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'
 ]

1 个答案:

答案 0 :(得分:0)

尝试从以下位置更改网址

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

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