繁体   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