我正在使用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'
]
答案 0 :(得分:0)
尝试从以下位置更改网址
url(r'^employees/', views.employeeList.as_view())
到
url(r'^employees/$', views.employeeList.as_view(), name='employees' )