修复若干bug,优化若干代码
This commit is contained in:
@@ -0,0 +1,16 @@
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.conf import settings
|
||||
import os, time, random,hashlib
|
||||
from django.http import HttpResponse
|
||||
|
||||
|
||||
class ImageStorage(FileSystemStorage):
|
||||
def __init__(self, location=settings.MEDIA_ROOT, base_url=settings.MEDIA_URL):
|
||||
super(ImageStorage, self).__init__(location, base_url)
|
||||
def _save(self, name, content):
|
||||
ext = os.path.splitext(name)[1]
|
||||
d = os.path.dirname(name)
|
||||
md5hash = hashlib.md5((os.path.basename(name) + str(time.time())).encode("utf-8"))
|
||||
fn = md5hash.hexdigest()
|
||||
name = os.path.join(d, fn + ext)
|
||||
return super(ImageStorage, self)._save(name, content)
|
||||
Reference in New Issue
Block a user