django tastypie图片上传angularjs

时间:2014-04-04 11:32:44

标签: python django angularjs tastypie

我正在使用angularjs,django和tastypie,如何使用python / django tastypie上传图像。我在我的api中得到cover: null,

class InventoryResource(ModelResource):
    cover = fields.FileField(attribute='cover', null=True, blank=True)

class Meta:
    queryset = Inventory.objects.all()
    resource_name = 'inventory'
    list_allowed_methods = ['get', 'put', 'post', 'delete', 'copy']
    detail_allowed_methods = ['get', 'put', 'post', 'delete', 'copy']
    authorization = DjangoAuthorization()
    authorization = Authorization()

模型:

class Inventory(models.Model):
    manufacturer = models.CharField(max_length=255,  help_text="Enter inventory name")
    cover        = models.FileField(upload_to = 'static/images/', default = 'static/images/no-image.png')
    created      = models.DateTimeField(auto_now_add=True)
   )

def __unicode__(self):
    return '%s' % self.manufacturer

1 个答案:

答案 0 :(得分:1)

使用angularjs和django tastypie无法上传文件。你需要从angularjs和tastypie环境中做到这一点。

创建专门用于上传的Django视图(在documentation阅读更多内容),并使用angularjs指令进行上传,例如:this directive