1. Related Downloads
- Download
dropzone.js
file: https://gitlab.com/meno/dropzone/-/jobs/79974233/artifacts/file/dist/dropzone.js
dropzone.css
: F12 take out the style and save to static/css directory;
2. Front-end style loading
4. Custom label, generate Li's id attribute using
from django.template import Libraryregister = Library()@register.simple_tagdef replace_str(s): return str(s).replace('.','_')
5. Routing Configuration
url(r'^enroll/(\d+)/file_upload/$', views.enroll_file_upload, name='enroll_file_upload'),
6. File Upload path configuration settings.py
ORM_PATH_DIR = os.path.join(BASE_DIR,'crm/upload_files/enrollment_data/')
7. View function
# Upload file configuration import osfrom Django import conffrom django.shortcut import render,httpresponseimport jsondef enroll_file_upload (Request, ENROLLMENT_ID): # Save the file, the corresponding folder is saved to the folder, the folder does not exist first enrollment_upload_dir = Os.path.join (conf.settings.ORM_ Path_dir, enrollment_id) if not Os.path.isdir (Enrollment_upload_dir): Os.mkdir (Enrollment_upload_dir) File_ob j = Request. Files.get (' file ') # limits the number of uploaded files to 2 if Len (Os.listdir (enrollment_upload_dir)) <= 2:with Open (os.path.join (Enrollment_upload_dir, File_obj.name), "WB") as f:for chunks in file_obj.chunks (): F.write (Chu nks) Else:return HttpResponse ({' Status ': False, ' err_msg ': ' Up to two uploads '}) return HttpResponse (JSON.D Umps ({' Status ': True,}) # delete file config def enroll_file_delete (request,stu_id,file_name): File_path = Os.path.join (conf.s Ettings. Orm_path_dir,stu_id,file_name) if Os.path.exists (File_path): Os.remove (File_path) if Request.is_ajax (): Return HttpResponse (Json.dumps ({' Status ': True, ' file_id ': str (file_name). Replace ('. ', ' _ ')}) return to else: Print (' No such file:%s '% File_path) return HttpResponse (Json.dumps ({' Status ': False, ' error_msg ': ' No file Found '})//Fetch List of the corresponding folder contents, placed in the main view function from Django import confimport osenrollment_upload_dir = Os.path.join (Conf.settings.ORM_PATH_DIR, ID) if Os.path.isdir (Enrollment_upload_dir): Upload_files=os.listdir (Enrollment_upload_dir)
File Upload plugin dropzone