API 处的属性错误 - 模块 object 没有属性 'UserViewSet' - Django Rest Framework
Attribute Error at API - module object has no attribute 'UserViewSet' - Django Rest Framework
设置 Django Rest 框架 -
使用 http://www.django-rest-framework.org/tutorial/quickstart/
中的快速入门教程
用户和组link按预期工作。我必须添加另一个 link - 按照相同的教程对我的应用程序和模型使用适当的命名约定,我得到了标题中列出的错误。
我可以注释掉用户和组,员工模型将起作用。我无法在 Django Rest 框架中获得超过一个 link 来正常工作。有任何想法吗?这是网址代码
from django.conf.urls import url, include
from rest_framework import routers
from XXXXXXaccess import views
from employees import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'employees', views.EmployeeViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
我发现您的导入有歧义。您可以显式导入名称: from XXXXXXaccess.views import UserViewSet 吗?否则,您将使用员工的视图定义覆盖视图,其中没有定义 UserViewSet,如错误所述。
from django.conf.urls import url, include
from rest_framework import routers
from XXXXXXaccess.views import UserViewSet, GroupViewSet
from employees.views import EmployeeViewSet
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
router.register(r'employees', EmployeeViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
设置 Django Rest 框架 -
使用 http://www.django-rest-framework.org/tutorial/quickstart/
中的快速入门教程用户和组link按预期工作。我必须添加另一个 link - 按照相同的教程对我的应用程序和模型使用适当的命名约定,我得到了标题中列出的错误。
我可以注释掉用户和组,员工模型将起作用。我无法在 Django Rest 框架中获得超过一个 link 来正常工作。有任何想法吗?这是网址代码
from django.conf.urls import url, include
from rest_framework import routers
from XXXXXXaccess import views
from employees import views
router = routers.DefaultRouter()
router.register(r'users', views.UserViewSet)
router.register(r'groups', views.GroupViewSet)
router.register(r'employees', views.EmployeeViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]
我发现您的导入有歧义。您可以显式导入名称: from XXXXXXaccess.views import UserViewSet 吗?否则,您将使用员工的视图定义覆盖视图,其中没有定义 UserViewSet,如错误所述。
from django.conf.urls import url, include
from rest_framework import routers
from XXXXXXaccess.views import UserViewSet, GroupViewSet
from employees.views import EmployeeViewSet
router = routers.DefaultRouter()
router.register(r'users', UserViewSet)
router.register(r'groups', GroupViewSet)
router.register(r'employees', EmployeeViewSet)
urlpatterns = [
url(r'^', include(router.urls)),
url(r'^api/', include(router.urls)),
url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework'))
]