I am new to Django and trying to save image to database i have written few lines code, which are not showing any error but are not able to save image to database.
View:-
def IndexView(request):
print("index view..")
if request.method == 'POST':
print("post")
form = ImageForm(request.POST, request.FILES)
print("form {}".format(form))
if form.is_valid():
print("valid..")
form.save()
form = ImageForm()
return render(request, "index.html")
my template:-
<div class="container">
<form enctype="multipart/form-data" action="" method="post">
{% csrf_token%}
<hr><br><br>
<input type="file" name="" id="" required/>
<br><br>
<input type="submit" class="btn btn danger" value="Upload">
</form>
</div>
model:-
class MyImage(models.Model):
image = models.ImageField(upload_to="myimage")
name = models.CharField(max_length=200, blank=True, default="")
Hope to here from you soon Thanks in advance