标签:ocs queryset alt log ges frame hostname ati cut
自动生成接口说明文档pip install djangorestframework
from rest_framework.documentation import include_docs_urls
path(‘docs/‘, include_docs_urls(title=‘文档‘)),
from django.db import models
# Create your models here.
class Asset(models.Model):
hostname = models.CharField(max_length=64, verbose_name=‘主机名‘, unique=True)
ip = models.CharField(max_length=30, verbose_name=‘ip‘, blank=True, null=True, )
class Meta:
db_table = "asset"
verbose_name = "asset"
verbose_name_plural = verbose_name
def __str__(self):
return self.hostname
from rest_framework import serializers
from .models import Asset
class AssetSerializer(serializers.ModelSerializer):
hostname = serializers.CharField(help_text=‘主机‘)
class Meta:
model = Asset
fields = ‘__all__‘
import json
from django.shortcuts import HttpResponse
from rest_framework import permissions
from rest_framework import generics
from rest_framework.views import APIView
from .serializers import AssetSerializer
from .models import Asset
class AssetInfo(generics.ListCreateAPIView):
"""
资产
"""
queryset = Asset.objects.get_queryset().order_by(‘id‘)
serializer_class = AssetSerializer
permission_classes = (permissions.IsAdminUser,)
http://127.0.0.1:8000/docs/
django-rest-framework 自动生成接口说明文档
标签:ocs queryset alt log ges frame hostname ati cut
原文地址:http://blog.51cto.com/hequan/2316781