0

我在输入http://127.0.0.1:8000/api/student/这个 URL 时遇到这个错误在此处输入图像描述

我的数据库:

在此处输入图像描述

帖子/模型.py

from django.db import models

class Student(models.Model):

lname = models.CharField(max_length=50)
fname=models.CharField(max_length=50)



 def __str__(self):
   return self.lname

帖子/序列化程序.py(webapp)

from rest_framework import serializers
from . import models


class StudentSerializer(serializers.ModelSerializer):

class Meta:
    fields = ('lname','fname',)
    model = models.Student 

帖子\filters.py(webapp)

from django_filters import rest_framework as filters

from .models import Student


class StudentFilter(FilterSet):
    total = filters.NumberFilter(name='total')
    class Meta:
    model = Student
    fields = ['lname','fname','total',]#other fields

帖子\views.py(网络应用程序)

from rest_framework import generics
from django.db.models import Count

from .models import Post,Student,Exam,Sample
from .serializers import PostSerializer,StudentSerializer,ExamSerializer,SampleSerializer
from django_filters.rest_framework import DjangoFilterBackend
#import django_filters.rest_framework
from django.db import connection


class StudentList(generics.ListAPIView):

   serializer_class = StudentSerializer
   def get_queryset(self):
   return 
Student.objects.all().values('fname').annotate(total=Count('fname')).order_by('total') 

帖子\urls.py(webapp)

from django.urls import path

from . import views

urlpatterns = [
           path('', views.PostList.as_view()),
           path('<int:pk>/', views.PostDetail.as_view()),
           path('student/',views.StudentList.as_view()),
           path('exam/',views.ExamList.as_view()),
          path('sam/',views.SampleList.as_view())
]   

示例项目(urls.py)

from django.contrib import admin
from django.urls import include, path


urlpatterns = [
    path('admin/', admin.site.urls),
    path('api/', include('posts.urls')),
]
 I got output in the shell but I couldn't get the same value in the browser (API)

在此处输入图像描述

4

0 回答 0