【问题标题】:django tastypie image upload angularjsdjango sweetpie 图片上传 angularjs
【发布时间】:2014-04-04 11:32:44
【问题描述】:

我正在使用 angularjs、django 和一个 sweetpie,如何使用 python/django sweetpie 上传图像。我在我的 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

【问题讨论】:

    标签: python django angularjs tastypie


    【解决方案1】:

    使用 angularjs 和 django tastepie 无法上传文件。您需要在 angularjs 和 sweetpie 上下文之外执行此操作。

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

    【讨论】:

      猜你喜欢
      • 2014-08-03
      • 2014-03-15
      • 2014-03-20
      • 1970-01-01
      • 2013-01-09
      • 2015-10-02
      • 2019-05-19
      • 1970-01-01
      • 2012-04-03
      相关资源
      最近更新 更多