gpt4 book ai didi

django - React.js 基于 DRF HTTP OPTIONS 动态生成表单

转载 作者:行者123 更新时间:2023-12-03 13:31:52 25 4
gpt4 key购买 nike

是否有基于 django-rest-framework OPTIONS 在 React 中渲染表单的包?

我的意思是让表单基于如下所示的方式呈现:

{
"name": "Spots Rating List",
"description": "",
"renders": [
"application/json",
"text/html"
],
"parses": [
"application/json",
"application/x-www-form-urlencoded",
"multipart/form-data"
],
"actions": {
"POST": {
"pk": {
"type": "integer",
"required": false,
"read_only": true,
"label": "ID"
},
"created_at": {
"type": "datetime",
"required": false,
"read_only": true,
"label": "Created at"
},
"updated_at": {
"type": "datetime",
"required": false,
"read_only": true,
"label": "Updated at"
},
"is_enabled": {
"type": "choice",
"required": false,
"read_only": false,
"label": "Is enabled",
"choices": [
{
"value": false,
"display_name": "Not allowed"
},
{
"value": true,
"display_name": "Allowed"
}
]
},
"friendly_rate": {
"type": "choice",
"required": true,
"read_only": false,
"label": "Friendly rate",
"choices": [
{
"value": 1,
"display_name": "terrible"
},
{
"value": 2,
"display_name": "poor"
},
{
"value": 3,
"display_name": "average"
},
{
"value": 4,
"display_name": "very good"
},
{
"value": 5,
"display_name": "excellent"
}
]
},
"opinion": {
"type": "nested object",
"required": false,
"read_only": true,
"label": "Opinion",
"children": {
"pk": {
"type": "field",
"required": true,
"read_only": false,
"label": "Rating"
},
"created_at": {
"type": "datetime",
"required": false,
"read_only": true,
"label": "Created at"
},
"updated_at": {
"type": "datetime",
"required": false,
"read_only": true,
"label": "Updated at"
},
"opinion_text": {
"type": "string",
"required": true,
"read_only": false,
"label": "Opinion text",
"max_length": 500
}
}
},
"tags": {
"type": "field",
"required": false,
"read_only": false,
"label": "Tags"
},
"user": {
"type": "field",
"required": false,
"read_only": true,
"label": "User"
}
}
}
}

网上没有任何引用。大多数都是硬编码的组件,对我来说丑陋且可怜...... https://www.valentinog.com/blog/tutorial-api-django-rest-react/#Django_REST_with_React_building_a_React_form

或者,如果至少能够获得为表单生成的组件代码,那也没关系。

最佳答案

我知道这不是完整的答案,但值得注意DRF Schema Adapter该项目旨在为前端框架导出此 DRF 元数据功能。目前,它仅适用于 Ember 和 Angular,但似乎为 React 编写自己的适配器并不难,因为它提供了与 React 一起使用的 MobxAxiosAdapter。

即使您没有资源来开发这样的东西,您也可以为这个库添加书签并等待React中的表单得到支持。

关于django - React.js 基于 DRF HTTP OPTIONS 动态生成表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49626935/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com