实例介绍
Django Ninja - 快速Django REST框架
Django Ninja是一个用于使用Django和Python 3.6 类型提示构建API的Web框架。其主要特点包括易用性、高性能(得益于Pydantic和异步支持)、类型提示和自动文档,符合开放API标准(先前称为Swagger)和JSON模式,以及与Django核心和ORM良好集成。
文档:https://django-ninja.dev
安装:pip install django-ninja
使用:在您的Django项目中,在urls.py旁边创建新的api.py文件:
from ninja import NinjaAPI api = NinjaAPI() @api.get("/add") def add(request, a: int, b: int): return {"result": a b}
【实例截图】
【核心代码】
文件清单
└── django-ninja-c6d44b62a180fcf8ddfd73d67e0274a77b9d30ae
├── CONTRIBUTING.md
├── docs
│ ├── docs
│ │ ├── extra.css
│ │ ├── guides
│ │ │ ├── api-docs.md
│ │ │ ├── async-support.md
│ │ │ ├── authentication.md
│ │ │ ├── errors.md
│ │ │ ├── input
│ │ │ │ ├── body.md
│ │ │ │ ├── file-params.md
│ │ │ │ ├── filtering.md
│ │ │ │ ├── form-params.md
│ │ │ │ ├── operations.md
│ │ │ │ ├── path-params.md
│ │ │ │ ├── query-params.md
│ │ │ │ └── request-parsers.md
│ │ │ ├── response
│ │ │ │ ├── config-pydantic.md
│ │ │ │ ├── django-pydantic-create-schema.md
│ │ │ │ ├── django-pydantic.md
│ │ │ │ ├── index.md
│ │ │ │ ├── pagination.md
│ │ │ │ ├── response-renderers.md
│ │ │ │ └── temporal_response.md
│ │ │ ├── routers.md
│ │ │ ├── testing.md
│ │ │ ├── urls.md
│ │ │ └── versioning.md
│ │ ├── help.md
│ │ ├── img
│ │ │ ├── auth-swagger-ui.png
│ │ │ ├── auth-swagger-ui-prompt.png
│ │ │ ├── benchmark.png
│ │ │ ├── body-editor.gif
│ │ │ ├── body-schema-doc2.png
│ │ │ ├── body-schema-doc.png
│ │ │ ├── deprecated.png
│ │ │ ├── docs-logo.png
│ │ │ ├── favicon.png
│ │ │ ├── github-star.png
│ │ │ ├── hero.png
│ │ │ ├── index-swagger-ui.png
│ │ │ ├── logo-big.png
│ │ │ ├── nested-routers-swagger.png
│ │ │ ├── operation_description_docstring.png
│ │ │ ├── operation_description.png
│ │ │ ├── operation_summary_default.png
│ │ │ ├── operation_summary.png
│ │ │ ├── operation_tags.png
│ │ │ ├── servers.png
│ │ │ ├── simple-routers-swagger.png
│ │ │ └── tutorial-path-swagger.png
│ │ ├── index.md
│ │ ├── motivation.md
│ │ ├── proposals
│ │ │ ├── cbv.md
│ │ │ ├── index.md
│ │ │ └── v1.md
│ │ ├── reference
│ │ │ ├── api.md
│ │ │ ├── csrf.md
│ │ │ ├── management-commands.md
│ │ │ ├── operations-parameters.md
│ │ │ └── settings.md
│ │ ├── releases.md
│ │ ├── tutorial
│ │ │ ├── index.md
│ │ │ ├── other
│ │ │ │ ├── crud.md
│ │ │ │ └── video.md
│ │ │ ├── step2.md
│ │ │ └── step3.md
│ │ └── whatsnew_v1.md
│ ├── mkdocs.yml
│ ├── requirements.txt
│ └── src
│ ├── index001.py
│ └── tutorial
│ ├── authentication
│ │ ├── apikey01.py
│ │ ├── apikey02.py
│ │ ├── apikey03.py
│ │ ├── basic01.py
│ │ ├── bearer01.py
│ │ ├── bearer02.py
│ │ ├── code001.py
│ │ ├── code002.py
│ │ ├── global01.py
│ │ ├── multiple01.py
│ │ └── schema01.py
│ ├── body
│ │ ├── code01.py
│ │ ├── code02.py
│ │ └── code03.py
│ ├── form
│ │ ├── code01.py
│ │ ├── code02.py
│ │ └── code03.py
│ ├── path
│ │ ├── code010.py
│ │ ├── code01.py
│ │ └── code02.py
│ └── query
│ ├── code010.py
│ ├── code01.py
│ ├── code02.py
│ └── code03.py
├── LICENSE
├── Makefile
├── mypy.ini
├── ninja
│ ├── compatibility
│ │ ├── __init__.py
│ │ └── util.py
│ ├── conf.py
│ ├── constants.py
│ ├── decorators.py
│ ├── errors.py
│ ├── files.py
│ ├── filter_schema.py
│ ├── __init__.py
│ ├── main.py
│ ├── management
│ │ ├── commands
│ │ │ ├── export_openapi_schema.py
│ │ │ └── __init__.py
│ │ ├── __init__.py
│ │ └── utils.py
│ ├── openapi
│ │ ├── docs.py
│ │ ├── __init__.py
│ │ ├── schema.py
│ │ ├── urls.py
│ │ └── views.py
│ ├── operation.py
│ ├── orm
│ │ ├── factory.py
│ │ ├── fields.py
│ │ ├── __init__.py
│ │ ├── metaclass.py
│ │ └── shortcuts.py
│ ├── pagination.py
│ ├── params
│ │ ├── functions.py
│ │ ├── __init__.py
│ │ └── models.py
│ ├── parser.py
│ ├── py.typed
│ ├── renderers.py
│ ├── responses.py
│ ├── router.py
│ ├── schema.py
│ ├── security
│ │ ├── apikey.py
│ │ ├── base.py
│ │ ├── http.py
│ │ ├── __init__.py
│ │ └── session.py
│ ├── signature
│ │ ├── details.py
│ │ ├── __init__.py
│ │ └── utils.py
│ ├── static
│ │ └── ninja
│ │ ├── favicon.png
│ │ ├── redoc.standalone.js
│ │ ├── redoc.standalone.js.map
│ │ ├── swagger-ui-bundle.js
│ │ ├── swagger-ui-bundle.js.map
│ │ ├── swagger-ui.css
│ │ ├── swagger-ui.css.map
│ │ └── swagger-ui-init.js
│ ├── templates
│ │ └── ninja
│ │ ├── redoc_cdn.html
│ │ ├── redoc.html
│ │ ├── swagger_cdn.html
│ │ └── swagger.html
│ ├── testing
│ │ ├── client.py
│ │ └── __init__.py
│ ├── types.py
│ └── utils.py
├── pyproject.toml
├── README.md
├── scripts
│ └── build-docs.sh
└── tests
├── conftest.py
├── demo_project
│ ├── demo
│ │ ├── asgi.py
│ │ ├── __init__.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ ├── manage.py
│ ├── multi_param
│ │ ├── api.py
│ │ ├── asgi.py
│ │ ├── __init__.py
│ │ ├── manage.py
│ │ ├── settings.py
│ │ ├── urls.py
│ │ └── wsgi.py
│ └── someapp
│ ├── admin.py
│ ├── api.py
│ ├── __init__.py
│ ├── models.py
│ └── views.py
├── env-matrix
│ ├── create_docker.py
│ ├── docker-compose.yml
│ ├── Dockerfile
│ ├── Dockerfile.backup
│ ├── install_env.sh
│ ├── README.md
│ └── run.sh
├── main.py
├── mypy_test.py
├── pytest.ini
├── test_alias.py
├── test_annotated.py
├── test_api_instance.py
├── test_app.py
├── test_async.py
├── test_auth_async.py
├── test_auth_global.py
├── test_auth_inheritance_routers.py
├── test_auth.py
├── test_auth_routers.py
├── test_body.py
├── test_conf.py
├── test_csrf_async.py
├── test_csrf.py
├── test_decorators.py
├── test_django_models.py
├── test_docs
│ ├── __init__.py
│ ├── test_auth.py
│ ├── test_body.py
│ ├── test_form.py
│ ├── test_index.py
│ ├── test_path.py
│ └── test_query.py
├── test_enum.py
├── test_errors.py
├── test_exceptions.py
├── test_export_openapi_schema.py
├── test_files.py
├── test_filter_schema.py
├── test_forms_and_files.py
├── test_forms.py
├── test_inheritance_routers.py
├── test_lists.py
├── test_misc.py
├── test_models.py
├── test_openapi_docs.py
├── test_openapi_extra.py
├── test_openapi_params.py
├── test_openapi_schema.py
├── test_orm_metaclass.py
├── test_orm_relations.py
├── test_orm_schemas.py
├── test_pagination_async.py
├── test_pagination.py
├── test_pagination_router.py
├── test_parser.py
├── test_path.py
├── test_pydantic_migrate.py
├── test_query.py
├── test_query_schema.py
├── test_renderer.py
├── test_request.py
├── test_response_cookies.py
├── test_response_multiple.py
├── test_response_params.py
├── test_response.py
├── test_reverse.py
├── test_router_path_params.py
├── test_schema_context.py
├── test_schema.py
├── test_server.py
├── test_signature_details.py
├── test_test_client.py
├── test_union.py
├── test_utils.py
├── test_with_django
│ ├── __init__.py
│ ├── schema_fixtures
│ │ ├── test-multi-body-file.json
│ │ ├── test-multi-body-form-file.json
│ │ ├── test-multi-body-form.json
│ │ ├── test-multi-body.json
│ │ ├── test-multi-cookie.json
│ │ ├── test-multi-form-body-file.json
│ │ ├── test-multi-form-body.json
│ │ ├── test-multi-form-file.json
│ │ ├── test-multi-form.json
│ │ ├── test-multi-header.json
│ │ ├── test-multi-path.json
│ │ └── test-multi-query.json
│ └── test_multi_param_parsing.py
└── test_wraps.py
42 directories, 266 files
小贴士
感谢您为本站写下的评论,您的评论对其它用户来说具有重要的参考价值,所以请认真填写。
- 类似“顶”、“沙发”之类没有营养的文字,对勤劳贡献的楼主来说是令人沮丧的反馈信息。
- 相信您也不想看到一排文字/表情墙,所以请不要反馈意义不大的重复字符,也请尽量不要纯表情的回复。
- 提问之前请再仔细看一遍楼主的说明,或许是您遗漏了。
- 请勿到处挖坑绊人、招贴广告。既占空间让人厌烦,又没人会搭理,于人于己都无利。
关于好例子网
本站旨在为广大IT学习爱好者提供一个非营利性互相学习交流分享平台。本站所有资源都可以被免费获取学习研究。本站资源来自网友分享,对搜索内容的合法性不具有预见性、识别性、控制性,仅供学习研究,请务必在下载后24小时内给予删除,不得用于其他任何用途,否则后果自负。基于互联网的特殊性,平台无法对用户传输的作品、信息、内容的权属或合法性、安全性、合规性、真实性、科学性、完整权、有效性等进行实质审查;无论平台是否已进行审查,用户均应自行承担因其传输的作品、信息、内容而可能或已经产生的侵权或权属纠纷等法律责任。本站所有资源不代表本站的观点或立场,基于网友分享,根据中国法律《信息网络传播权保护条例》第二十二与二十三条之规定,若资源存在侵权或相关问题请联系本站客服人员,点此联系我们。关于更多版权及免责申明参见 版权及免责申明
网友评论
我要评论