如何将JSON数据查找为余烬欲望?

2024-09-26 18:04:32 发布

您现在位置:Python中文网/ 问答频道 /正文

我是django的新人余烬. 你能帮我找到正确的JSOn吗余烬在

我的密码在这里-

在模型.py-在

from django.db import models

class Confusion(models.Model):

title = models.CharField(max_length=100)
description = models.CharField(max_length=100)

在序列化程序.py-在

^{pr2}$

在视图.py-在

from rest_framework import generics

from confusion.models import Confusion

from confusion.serializers import ConfusionSerializer

class ConfusionList(generics.ListCreateAPIView):

    queryset = Confusion.objects.all()
    serializer_class = ConfusionSerializer

class ConfusionDetail(generics.RetrieveUpdateDestroyAPIView):

    queryset = Confusion.objects.all()
    serializer_class = ConfusionSerializer

现在我得到的输出是-

[{"id": 1, "title": "Career", "description": "I am confused about my career"}]

但我需要:

{"confusion":{"id": 1, "title": "Career", "description": "I am confused about my career"}}

Tags: djangofrompyimporttitlemodelsdescriptionmax
1条回答
网友
1楼 · 发布于 2024-09-26 18:04:32

看看托兰·比卢普斯的ember-data-django-rest-adapter。它应该能满足你的需要。在

看看README-对于基本用途,所有额外的设置都在JavaScript端。在

(我基本上是引用…)

  1. 在HTML/构建系统中包含ember-data.js之后的ember-data-django-rest-adapter.js

  2. 添加自定义适配器:

     App.Store = DS.DjangoRESTStore.extend({
        adapter: DS.DjangoRESTAdapter.create()
     });
    

就这样。(特别是有什么事情你不能工作吗?)在

相关问题 更多 >

    热门问题