I'm trying to upload some files and I'm having problems with duplication.
To uploading the file I do the following:
views.py:
from django.core.files.storage import FileSystemStorage
def contView(request):
if request.method == 'POST' and request.FILES.get('myfile'):
myfile = request.FILES['myfile']
fs = FileSystemStorage()
filename = fs.save('uploads/'+myfile.name, myfile)
uploaded_file_url = fs.url(filename)
# Return
template_name ='cont/mainCont.html'
context = {}
return render(request, template_name, context)
Template:
<form method="post" enctype="multipart/form-data">{% csrf_token %}
<div class="input-group">
<input type="file" name="myfile" class="form-control">
<span class="input-group-btn">
<button class="btn btn-default" type="submit">Importar</button>
</span>
</div>
</form>
The upload works perfectly but when I refresh the page it upload the same file again. Why is this happening? I need to empty something?
Thank you very much!
question from:
https://stackoverflow.com/questions/65925084/uploading-duplicated-files-with-django-when-reloading-page 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…