Answer the question
In order to leave comments, you need to log in
How to implement file upload to server in Django?
It is necessary to implement uploading files to the server by the user through a form. For some reason, there is not much information in the Django documentation on this topic and it was not enough for me to figure it out. If it doesn’t make it difficult, then I will be happy with a ready-made simple example, which I would already have reworked to fit my needs. Thanks in advance
Answer the question
In order to leave comments, you need to log in
From docs :
# In forms.py...
from django import forms
class UploadFileForm(forms.Form):
title = forms.CharField(max_length=50)
file = forms.FileField()
from django.http import HttpResponseRedirect
from django.shortcuts import render
from .forms import UploadFileForm
def upload_file(request):
if request.method == 'POST':
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect('/success/url/')
return render(request, 'upload.html', {'form': form})
else:
form = UploadFileForm()
return render(request, 'upload.html', {'form': form})
It's not clear how to send or receive a file? .... Google did not help?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question