我多次查看这些行,并在网站上搜索以找到类似的问题,但我无法找出我遗漏了什么导致了错误
url.py-profiles\u api
from django.urls import path
from profiles_api import views
urlpatterns = [
path('hello-view/', views.HelloApiView.as_View()),
]
views.py-profiles\u api
from rest_framework.views import APIView
from rest_framework.response import Response
class HelloApiView(APIView):
"""test API View"""
def get(self, request, format=None):
"""Returns a list of APIView features"""
an_apiview = [
'Uses HTTP methods as function (get, post, patch, put, delete)',
'Is similar to a traditional Django View',
'Gives you the most control over your application logic',
'Is mapped manually to URLs',
]
return Response({'message': 'Hello!', 'an_apiview': an_apiview})
url.py-profiles\u项目
from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('profiles_api.urls'))
]
例外情况:
(env) vagrant@ubuntu-bionic:/vagrant$ python manage.py runserver 0.0.0.0:8080
....
path('hello-view/', views.HelloApiView.as_View()),
AttributeError: type object 'HelloApiView' has no attribute 'as_View'
我猜是typo
as_view()
不是as_View()
As error表示没有属性As_视图。问题是大写的V。应该有
as_view()
相关问题 更多 >
编程相关推荐