1
我使用的是angularjs,django和tastypie,如何使用python/django tastypie上傳圖片。我在我的api中獲得cover: null,
。django tastypie圖片上傳angularjs
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