在Django-rest CreateAPIView中看不到表单

时间:2019-12-29 15:58:22

标签: django django-rest-framework django-views

我正在尝试查看CreateAPIView。我指的是以下tutorial。因此,如您在下图中所看到的,我可以得到与预期相似的页面,但是我看不到我们在其中输入数据的表单。现在,我认为可能是因为我尚未登录。但是我一直在尝试登录django-rest框架,即使在我登录的django-admin中,它也无法正常工作。终端的图像显示了当我尝试登录django-rest时得到响应。

image of api/booking/create webpage i.e. CreateAPIView

image of the terminal response

这是我的views.py

from django.shortcuts import render

# Create your views here.
from pool.models import Booking, Register
from pool.serializers import BookingSerializer, RegisterSerializer
from rest_framework import viewsets
from rest_framework.generics import ListCreateAPIView, RetrieveAPIView, CreateAPIView



class BookingListView(ListCreateAPIView):
    queryset = Booking.objects.all()
    serializer_class = BookingSerializer

class BookingDetailView(RetrieveAPIView):
    queryset = Booking.objects.all()
    serializer_class = BookingSerializer

class BookingCreateView(CreateAPIView):
    queryset = Booking.objects.all()
    serializer_class = BookingSerializer

class RegisterListView(ListCreateAPIView):
    queryset = Register.objects.all()
    serializer_class = RegisterSerializer

class RegisterDetailView(RetrieveAPIView):
    queryset = Register.objects.all()
    serializer_class = RegisterSerializer

class RegisterCreateView(CreateAPIView):
    queryset = Register.objects.all()
    serializer_class = RegisterSerializer

这是我的serializers.py

from rest_framework import serializers
from pool.models import Booking, Register

class BookingSerializer (serializers.ModelSerializer):
    class Meta:
        model = Booking;
        fields = '__all__'

class RegisterSerializer (serializers.ModelSerializer):
    class Meta:
        model = Register;
        fields = '__all__'

这是我的urls.py

from django.conf.urls import url
from django.urls import path
from . import views
from rest_framework import routers
# from . import views
from .views import (
    BookingCreateView,
    BookingListView,
    BookingDetailView,
    RegisterCreateView,
    RegisterListView,
    RegisterDetailView
    )
router.register(r'register', views.RegisterList)

urlpatterns = [
    path('booking/', BookingListView.as_view()),
    path('booking/create/', BookingCreateView.as_view()),
    path('booking/<pk>', BookingDetailView.as_view()),
    path('register/', RegisterListView.as_view()),
    path('register/create/', RegisterCreateView.as_view),
    path('register/<pk>', RegisterDetailView.as_view())
]

谢谢。

0 个答案:

没有答案