File Upload Plugin Dropzone

Source: Internet
Author: User
Tags configuration settings file url

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.