Skip to content Skip to sidebar Skip to footer

Django: Upload Image To Form

I am new to Django and am writing my first app. It is simple and you use a form to add a new 'client'. One of the fields is an ImageField, and after inputting the image, and subm

Solution 1:

I seems that you forgot to pass the request.FILES to your form.

Try this :

if request.method == 'POST':
        form = ClientForm(request.POST, request.FILES)

Here is an excellent example of file upload with django : Need a minimal Django file upload example

Solution 2:

Your error is here:

<imgsrc="{ picture }"alt="Client Photo">

You should use double brackets and the url() method as in:

<imgsrc="{{ picture.url }}"alt="Client Photo">

ImageFields are extended FieldFiles and you can access the relative url using url() method

Post a Comment for "Django: Upload Image To Form"