2014-04-04 108 views
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 

回答

1

上傳的文件是不可能的angularjs和Django的tastypie。您需要從angularjs和tastypie環境中完成。

創建您自己的專門用於上傳的Django視圖(請閱讀documentation),並使用angularjs指令上傳,例如:this directive