如何用Django tastypie发布?

2024-09-30 20:19:05 发布

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

我在我的项目中使用的是tastype,get-http方法工作得很好,但是当我尝试发布新数据时,我可以´电话:

from random import randint
from django.conf.urls import url
from tastypie import fields
from tastypie.utils import trailing_slash
from tastypie.resources import ModelResource
from device.models import Device
from tastypie.serializers import Serializer
from tastypie.authorization import Authorization, DjangoAuthorization


class DeviceResource(ModelResource):
    service = fields.ToOneField('services.api.resources.ServiceResource', 'service', null=True, blank=True)

class Meta:
    always_return_data = True
    queryset = Device.objects.all()
    fields = ['token', 'description', 'type', 'state','service']
    allowed_methods = ['get', 'post']
    resource_name = 'device'
    autorization = Authorization()

当前版本python 2.7.10 django 1.9 tastypie 0.13.3


Tags: 项目djangofromimporttruefieldsgetdevice