Python
1
Вклад в тег
class LoadNewForm(forms.Form):
file = forms.FileField(widget=forms.ClearableFileInput(attrs={'multiple': True}))
def load_new(request):
if request.method == "POST":
newtrack = forms.LoadNewForm(request.POST, request.FILES)
if newtrack.is_valid():
files = newtrack.files.getlist('file')
for f in files:
print(f.name)
data = {"header" : "Успешно загружены",}
else:
data = {"header" : "Ошибка проверки формы",}
else:
data = {
"header" : "Загрузить файлы",
"form" : forms.LoadNewForm(),}
return render(request, "load_new.html", context=data)
{% if form %}
<form method="POST" enctype="multipart/form-data">
<div class="form-group">
{% csrf_token %}
{{ form }}
<input class="btn btn-primary" type="submit" value="Send" >
</div>
</form>
{% endif %}