settings.py中设置upload路径
UPLOAD_ROOT = os.path.join(BASE_DIR,'upload')
url.py中设置
from django.urls import path,re_path
from django.views.static import serve
from ajaxpro.settings import UPLOAD_ROOT
re_path('^upload/(?P<path>.*)$',serve,{'document_root':UPLOAD_ROOT})
# 图片处理
def uploadimg(img):
f = open(os.path.join(settings.UPLOAD_ROOT,'',img.name),'wb')
for chunk in img.chunks():
f.write(chunk)
f.close()