标签:dcs 封装 启动服务 strip ges views models date 地址
pip install djangorestframework
python manage.py startapp idcs
class Idcs(model.Model):
name =CharField('机房名称',max_length=20)
address = models.CharField('机房地址',max_length=200)
phone = models.CharField('机房联系电话',max_length=15)
email = models.EmailField('机房联系 email')
letter = models.CharField('idc字母简称',max_length=5)
from from rest_framework import ModelSerializer
from .models import Idcs
class IdcSerializers(serializers.ModelSerializer):
class Meta:
model = Idcs
field = ('__all__')
#ModelSerializer是serializers的封装,简单实现了create,update方法
from rest_framework import viewsets
from .models import Idcs
from .serializer import IdcSerializers
class IdcListViewset(viewsets.ModelViewSet):
queryset = Idcs.objects.all()
serializer_class = IdcSerializers
from django.conf.urls import url,include
urlpatterns = [
url(r'^',include('idcs.urls')),
]
from django.conf.urls import url,include
from rest_framework.routers import DefaultRouter
route = DefaultRouter()
route.register("idcs",views.IdcListViewset)
urlpatterns = [
url(r'^',include(route.urls))
]
标签:dcs 封装 启动服务 strip ges views models date 地址
原文地址:https://www.cnblogs.com/guigujun/p/9190784.html