markdown Fluxo django-rest
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了markdown Fluxo django-rest相关的知识,希望对你有一定的参考价值。
## Cria o serializers dentro do app
```python
# app/serializers.py
from rest_framework import serializers
from .models import Category
class CategorySerializer(serializers.ModelSerializer):
class Meta:
model = Category
fields = ('id', 'name', 'description', 'created_at', 'updated_at')
```
## Cria o viewset
```python
# app/viewsets.py
from rest_framework import viewsets
from .serializers import CategorySerializer
from .models import Category
class CategoryViewSet(viewsets.ModelViewSet):
serializer_class = CategorySerializer
queryset = Category.objects.all()
```
## Registra as URLS
```python
# app_principal/urls.py
from django.contrib import admin
from django.urls import path, include
from rest_framework import routers
from api.viewsets import CategoryViewSet
router = routers.DefaultRouter()
router.register(r'categories', CategoryViewSet)
urlpatterns = [
path('admin/', admin.site.urls),
path(r'^api/', include(router.urls)),
]
```
以上是关于markdown Fluxo django-rest的主要内容,如果未能解决你的问题,请参考以下文章
markdown Fluxo de trabalho com redux
Django Rest Framework:非模型服务
自动化监控系统 搭建xadmin做网站后台
django-rest-swagger对API接口注释
Django RESTful Framework 如何从 HTTP 标头的令牌中获取用户模型?
有啥方法可以更改登录的 Django-rest-auth 视图?