I have this in Model
image_name = models.ImageField(upload_to='accounts/')
In my view I have
def account_form(request):
if request.method == 'POST': # If the form has been submitted...
form = AccountForm(request.POST) # A form bound to the POST data
if form.is_valid(): # All validation rules pass
form.save()
return HttpResponseRedirect('/thanks/') # Redirect after POST
else:
form = AccountForm() # An unbound form
return render_to_response('account_form.html', {
'form': form,
})
Do I need to do extra coding for saving image or django will do it itself
Also make sure your form enctype
is set in the HTML to submit file data:
<form action="..." method="POST" enctype="multipart/form-data">
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With