<p>我多次查看这些行,并在网站上搜索以找到类似的问题,但我无法找出我遗漏了什么导致了错误</p>
<p><strong>url.py-profiles\u api</strong></p>
<pre class="lang-py prettyprint-override"><code>from django.urls import path
from profiles_api import views
urlpatterns = [
path('hello-view/', views.HelloApiView.as_View()),
]
</code></pre>
<p>views.py-profiles\u api</p>
<pre><code>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})
</code></pre>
<p><strong>url.py-profiles\u项目</p>
<pre class="lang-py prettyprint-override"><code>from django.contrib import admin
from django.urls import path, include
urlpatterns = [
path('admin/', admin.site.urls),
path('api/', include('profiles_api.urls'))
]
</code></pre>
<p><strong>例外情况:</strong></p>
<blockquote>
<p>(env) vagrant@ubuntu-bionic:/vagrant$ python manage.py runserver 0.0.0.0:8080</p>
<p>....</p>
<p>path('hello-view/', views.HelloApiView.as_View()),</p>
<p>AttributeError: type object 'HelloApiView' has no attribute 'as_View'</p>
</blockquote>