Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7016321
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T22:46:10+00:00 2026-05-27T22:46:10+00:00

In my django application the form never returns true even if I add the

  • 0

In my django application the form never returns true even if I add the same data as in the admin application. My model.py looks like:

from django.db import models
from django.db.models import ImageField, signals
from django.dispatch import dispatcher
from django.forms import ModelForm

# Create your models here.
class Image(models.Model):
    emailAddress = models.EmailField(max_length=75)
    image = ImageField(upload_to='photos')
    caption = models.CharField(max_length=100)

class UploadForm(ModelForm):
    class Meta:
        model = Image

My views.py looks like:

from django.http import HttpResponse, HttpResponseRedirect
from django.shortcuts import render_to_response
from competition.models import Image, UploadForm

# Create your views here.

def index(request):
    images = Image.objects.all().order_by('emailAddress')
    return render_to_response('images/index.html', {'images': images})

def uploadImage(request):
    if request.method == 'POST': # If the form has been submitted...
        form = UploadForm(request.POST) # A form bound to the POST data
        if form.is_valid(): # All validation rules pass
            emailAddress = form.cleaned_data['emailAddress']
            image = form.cleaned_data['image']
            caption = form.cleaned_data['caption']
            i = Image(emailAddress=emailAddress, image = image, caption = caption)
            i.save()
            return HttpResponseRedirect('../image/')
        else:
            return render_to_response('images/upload.html', {'form': form})
    else:
        form = UploadForm() # An unbound form
        return render_to_response('images/upload.html', {'form': form})

My template looks like:

<html>
<body>
    <form enctype="multipart/form-data" action="/image/uploadImage" method="post">{% csrf_token %}
    {{ form.as_p }}
    <input type="submit" value="Submit" />
    </form>
    </body>
</html>

I can get it work correctly if I use the admin application but need a generic form and this does’t work as it keeps asking for a either the email address or image (the error appears above the image field). So why might my form not be valid?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T22:46:10+00:00Added an answer on May 27, 2026 at 10:46 pm

    You need to instantiate your form with request.FILES as well as request.POST.

    As an aside, you can save the model form instead of creating the Image by hand in the view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to fill a livecycle created form with form data from django.
I have a Django application which includes a custom model field (and accompanying form
I am building a relatively simple Django application and apart from the main page
I'm writing an application in django that needs to only allow a form to
I have this form in a Django application In Firefox it works as charm,
in my Django application I've got a form with a ChoiceField that normally allows
In a django application I have the following model: class Appointment(models.Model): #some other fields
so I'm working on a django application where I have a model Event. Each
In Django, given excerpts from an application animals likeso: A animals/models.py with: from django.db
I am trying to create a job application-form with Django. Basically, I created two

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.