URL文件
from django.contrib import adminfrom django.urls import pathfrom app01 import viewsurlpatterns = [ path('admin/', admin.site.urls), path('upload.html/', views.upload), path('upload_img.html/', views.upload_img),]
views文件
from django.shortcuts import render,HttpResponseimport json# Create your views here.def upload(request): return render(request,'upload.html')def upload_img(request): import os import uuid nid = str(uuid.uuid4()) ret = { 'status':True,'data':None,'message':None} obj = request.FILES.get('k3') file_path = os.path.join('static', nid+obj.name) f = open(file_path,'wb') for line in obj.chunks(): f.write(line) f.close() ret['data']=file_path return HttpResponse(json.dumps(ret))
html文件
Title
预览