我正在关注本教程 https://thinkster.io/django-angularjs-tutorial/。此刻我在this https://thinkster.io/django-angularjs-tutorial/#registering-new-users-checkpoint点但是当我启动我的服务器时python manage.py runserver 0.0.0.0:8000
并在浏览器中打开网址,我收到以下错误:
name 'IndexView' is not defined
这是我的 urls.py
from django.conf.urls import include, url
from django.contrib import admin
from django.conf.urls import patterns
from rest_framework_nested import routers
from authentication.views import AccountViewSet
router = routers.SimpleRouter()
router.register(r'accounts', AccountViewSet)
urlpatterns = patterns(
'',
url(r'^admin/', include(admin.site.urls)),
url(r'^api/v1/', include(router.urls)),
url('^.*$', IndexView.as_view(), name='index'),
)
我不知道如何解决这个问题,因为我什至从未见过自己声明过这一点IndexView
某处。如果你们能给我一些关于这个问题的建议,那就太好了。
Edit:
我的观点.py
from django.shortcuts import render
# Create your views here.
from rest_framework import permissions, viewsets
from authentication.models import Account
from authentication.permissions import IsAccountOwner
from authentication.serializers import AccountSerializer
class AccountViewSet(viewsets.ModelViewSet):
lookup_field = 'username'
queryset = Account.objects.all()
serializer_class = AccountSerializer
def get_permissions(self):
if self.request.method in permissions.SAFE_METHODS:
return (permissions.AllowAny(),)
if self.request.method == 'POST':
return (permissions.AllowAny(),)
return (permissions.IsAuthenticated(), IsAccountOwner(),)
def create(self, request):
serializer = self.serializer_class(data=request.data)
if serializer.is_valid():
Account.objects.create_user(**serializer.validated_data)
return Response(serializer.validated_data, status=status.HTTP_201_CREATED)
return Response({
'status': 'Bad request',
'message': 'Account could not be created with received data.'
}, status = status.HTTP_400_BAD_REQUEST)