本文整理汇总了Python中models.File.image方法的典型用法代码示例。如果您正苦于以下问题:Python File.image方法的具体用法?Python File.image怎么用?Python File.image使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.File
的用法示例。
在下文中一共展示了File.image方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: multiuploader
# 需要导入模块: from models import File [as 别名]
# 或者: from models.File import image [as 别名]
def multiuploader(request):
"""
Main Multiuploader module.
Parses data from jQuery plugin and makes database changes.
"""
if request.method == 'POST':
log.info('received POST to main multiuploader view')
if request.FILES == None:
return HttpResponseBadRequest('Must have files attached!')
#getting file data for farther manipulations
file = request.FILES[u'files[]']
wrapped_file = UploadedFile(file)
filename = wrapped_file.name
file_size = wrapped_file.file.size
log.info ('Got file: "%s"' % filename)
#writing file manually into model
#because we don't need form of any type.
image = File()
image.filename= filename
image.image=file
image.key_data = image.key_generate
image.save()
log.info('File saving done')
#settings imports
try:
file_delete_url = settings.MULTI_FILE_DELETE_URL+'/'
# file_url = settings.MULTI_IMAGE_URL+'/'+image.key_data+'/'
except AttributeError:
file_delete_url = 'multi_delete/'
# file_url = 'multi_image/'+image.key_data+'/'
file_url = image.image.url;
#generating json response array
result = []
context = {"name":filename,
"size":file_size,
"url":file_url,
"file_id": image.id,
"delete_url":file_delete_url+str(image.pk)+'/',
"delete_type":"POST",
}
#getting thumbnail url using sorl-thumbnail
print image.is_image
if image.is_image:
im = get_thumbnail(image, "80x80", quality=50)
context['thumbnail_url'] = im.url
result.append(context)
response_data = simplejson.dumps(result)
#checking for json data type
#big thanks to Guy Shapiro
if "application/json" in request.META['HTTP_ACCEPT_ENCODING']:
mimetype = 'application/json'
else:
mimetype = 'text/plain'
return HttpResponse(response_data, mimetype=mimetype)
else: #GET
return HttpResponse('Only POST accepted')