Answer the question
In order to leave comments, you need to log in
Django, how to add images to database?
Hello everyone, how to add adding images to the table? Here is the table:
class OurFoto(models.Model):
image = models.ImageField(height_field=200, width_field=200)
name = models.CharField(blank=False, max_length=100, unique=True)
date_added = models.DateTimeField(auto_now_add=True)
def __str__(self):
return self.image
def add_foto(request):
title = 'Добавление изображения'
form = None
if request.method == 'GET':
form = AddFotoForm()
if request.method == 'POST':
form = AddFotoForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('index'))
context = {'title': title, 'form': form}
return render(request, 'repository_our_fotos/add_foto.html', context)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question