Search code examples
djangoformspostviewcleaned-data

Object has no attribute cleaned_data


I am trying to fill out a form in my Django web application and post it. It is giving me an error

object Application has no attribute cleaned_data

I looked around Stack Overflow at similar questions, but the resolutions for others are not issues with my code. Here is my view:

def single_career(request, a_slug):
    a_slug = a_slug.strip('/')

    try:
        career = Career.objects.get(slug=a_slug)
    except:
        career = None

    if request.method == "POST":
        form = Application(request.POST, request.FILES)
        Post = True

        if form.is_valid():
            cleaned_data = Application.cleaned_data
            is_valid = True

            clean_first = cleaned_data['first_name']
            clean_last = cleaned_data['last_name']
            clean_email = cleaned_data['email']
            clean_phone = cleaned_data['phone']
            clean_file = cleaned_data['resume']
            clean_message = cleaned_data['message']
            date = datetime.datetime.now()

        else:
            is_valid = False

    else:
        form = Application()
        Post = False
        is_valid = False

    context = {'career': career, 'form': form, 'post': Post, 'is_valid': is_valid}

    template = 'overrides/careers.html'
    set_detail_context(request, context)

    return render_to_response(template, context, context_instance=RequestContext(request))

the html:

<form action="" method="POST" enctype="multipart/form-data" class="application-form">
    {% csrf_token %}
    <div class="firstname">
        <p>FIRST NAME</p>
        {{ form.first_name }}
    </div>
    <div class="lastname">
        <p>LAST NAME</p>
        {{ form.last_name }}
    </div>
    <div class="email">
        <p>EMAIL</p>
        {{ form.email }}
    </div>
    <div class="phone">
        <p>PHONE</p>
        {{ form.phone }}
    </div>

    {#  form fileupload-input is hidden, and extra readonly text-input is there #}
    {#  to be able to override the styling of the fileupload-input button       #}
    <div>
        <p>ATATCH PDF RESUME</p>
        <input class="readonly" type="text" READONLY>
        <div class="resume">
            {{ form.resume }}
            <div>
                <a id="browse">BROWSE</a>
            </div>
        </div>
    </div>

    <div>
        <p>MESSAGE</p>
        {{ form.message }}
    </div>
    <button class="submit-button" type="submit">
        APPLY
    </button>
</form>

and the form class:

from django import forms

class Application(forms.Form):
    first_name = forms.CharField(label="First Name", max_length=50)
    last_name = forms.CharField(label="Last Name", max_length=50)
    email = forms.EmailField(label="Email", max_length=80)
    phone = forms.CharField(label="Phone Number", max_length=30)
    resume = forms.FileField(label="Resume", max_length=1000)
    message = forms.CharField(label="Message", max_length=800, widget=forms.Textarea)

Solution

  • The validated form is form, not Application.