修复若干bug,优化若干代码

This commit is contained in:
ladeng07
2022-05-15 01:31:26 +08:00
parent bd36d90a3b
commit f65714f84e
26 changed files with 417 additions and 212 deletions
+16
View File
@@ -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)