I'am learning python and django, I want to make an endpoint that takes zip file and iterate through it and shows me the item list inside the zip file. What would be the easiest way to implement this? I have tried something, as my knowledge in django is not good at all.
from django.core.files.storage import FileSystemStorage
import zipfile
class Upload(View):
def post(self, request):
context = {}
if request.method == 'POST':
uploaded_file = request.FILES['filename']
zf = zipfile.ZipFile(uploaded_file)
print zf.namelist()
for filename in zf.namelist():
fs = FileSystemStorage()
rename = 'uploadedFile.jpg'
name = fs.save(rename, filename)
context['url'] = fs.url(name)
return render(request, 'app.html', context)
so basically my purpose is to take a zipfile from and rename it and makke an url for each. My stated code is not the right way to do this as its bringing some error, would you please help me with the right way?