• Django rest framework 应用解答


    Django rest framework 应用解答

    Django项目创建

    #django-admin startproject assets  //创建项目
    #cd assets
    #python manage.py startapp restfm  //创建应用app

    pip安装对应的framework包

    • 支持更好的前端交互,因此采用swagger
    #pip install django-rest-swagger==2.1.2    
    #pip install djangorestframework==3.7.3 

    setting中配置加入framework应用

    INSTALLED_APPS = [
        'django.contrib.admin',
        'django.contrib.auth',
        'django.contrib.contenttypes',
        'django.contrib.sessions',
        'django.contrib.messages',
        'django.contrib.staticfiles',
        'assets_control',
        'rest_framework',
    ]
    • framework配置信息:json、模板、分页功能
    #REST FRAMEWORK config info,with default page limit.
    REST_FRAMEWORK = {
    
        'TEST_REQUEST_RENDERER_CLASSES': (
            'rest_framework.renderers.MultiPartRenderer',
            'rest_framework.renderers.JSONRenderer',
            'rest_framework.renderers.TemplateHTMLRenderer'
        ),
        'DEFAULT_PAGINATION_CLASS': 'rest_framework.pagination.LimitOffsetPagination',
        'PAGE_SIZE': 100
    }

    采用默认swagger格式前端展示

    sweet-framework 
    POST /sweet-framework/cloud/error-report 发送用户错误报告
    GET /sweet-framework/cloud/hystrix/metrics 查询所有Hystrix统计指标
    GET /sweet-framework/cloud/security-rules 服务调用安全规则
    GET /sweet-framework/cloud/service-list 服务调用安全规则
    GET /sweet-framework/configuration/json 查询应用的配置参数
    GET /sweet-framework/configuration/namespaces 查询应用配置项命名空间
    GET /sweet-framework/errors/json 显示应用的错误码
    POST /sweet-framework/i18n/locale 改变后端响应消息的默认语言
    POST /sweet-framework/logger/config 配置日志级别
    GET /sweet-framework/logger/query 查询日志配置
    GET /sweet-framework/metrics 获取应用统计指标
    GET /sweet-framework/touch 应用活动检测

    根据需要使用自定义的swagger.json文件

    • 配置
    setting中设置指定swagger.json文件目录即可
    
    • 结果显示
    assets : 资产管理服务 Show/Hide List Operations Expand Operations
    GET /assets/room/list/ 查询资产中的机房列表信息
    POST /assets/room/create/ 创建机房信息
    GET /assets/room/detail/{id}/ 获取某个机房id 的详细信息
    DELETE /assets/room/detail/{id}/update/ 删除一个机房记录
    PUT /assets/room/detail/{id}/update/ 修改一个机房信息
  • 相关阅读:
    UVa 658 (Dijkstra) It's not a Bug, it's a Feature!
    CodeForces Round #288 Div.2
    UVa 540 (团体队列) Team Queue
    UVa 442 (栈) Matrix Chain Multiplication
    CodeForces Round #287 Div.2
    CodeForces Round #286 Div.2
    CodeForces Round #285 Div.2
    UVa 12096 (STL) The SetStack Computer
    UVa 101 (模拟) The Blocks Problem
    UVa 12171 (离散化 floodfill) Sculpture
  • 原文地址:https://www.cnblogs.com/zksfyz/p/9103839.html
Copyright © 2020-2023  润新知