object has no attribute 'cleanned_data'

Hi All,

I have to generate a quick form that is not based on a model, but rather just a form, and I followed the django tutorial

forms.py

class GenerateFormForecast(forms.Form):
    probability = forms.DecimalField(max_digits=2, decimal_places=2)
    number_of_payments = forms.IntegerField()
    revenue = forms.IntegerField()

views.py

@login_required
def data_form_forecast(request):
    #gets the project number
    project_id = request.GET.get('project_id')
    revenue = Leads.objects.get(pk=project_id)
    if request.method == "POST":
        form = GenerateFormForecast(request.POST)
        if form.is_valid():
            probability = form.cleaned_data["probability"]
            n = form.cleaned_data["number_of_payments"]
            revenue = form.cleanned_data["number_of_payments"]

            context = {
                "id":project_id,
                "probability":probability,
                "n":n,
                "revenue":revenue
            }

            return render(request,"account/leadentry_update.html",context)
    else:
        initial = {'revenue':int(revenue.expected_revenue.amount)}

        form = GenerateFormForecast(initial=initial)

    context = {
        'form': form
    }
    return render(request, "account/lead_forecast.html", context)

HTML


<h1> Add Lead to Sales Forecast </h1>
  <h2>Enter Payment Details</h2>
  <br>

  <div class="container-fluid">
        <form method="POST">
            {% csrf_token %}

            <div class="row justify-content-center">

                <div class="col-sm-1">
                {{ form.number_of_payments|as_crispy_field }}
                </div>
                <div class="col-sm-1">
                {{ form.revenue|as_crispy_field }}
                </div>
                <div class="col-sm-1">
                {{ form.probability|as_crispy_field }}
                </div>
                <div class="col-sm">
                    <button type="submit" class="buttons"> Submit </button>
                </div>
            </div>
            <hr>

        </form>
    </div>



    </div>

After running the sever, the form is presented ok, with the revenue field populated but once I post some new data, I’m getting the following error: AttributeError: ‘GenerateFormForecast’ object has no attribute ‘cleanned_data’

the django TUtorial specifies that the cleaned_data function goes after form.is_valid:

if form.is_valid():
# process the data in form.cleaned_data as required
# …
# redirect to a new URL:
return HttpResponseRedirect(’/thanks/’)

what am I doing wrong?,

read the error more carefully. It’s referring to cleanned_data (note the extra n)

Also, generally it’s more helpful to post the entire traceback when asking for help. Most likely in this case, the traceback includes the exact line of code of the exception. That can be a helpful clue for debugging.

1 Like