Django AttributeError: calling form.is_valid() always results in Object has no attribute 'is_vaild'

django, django-forms, forms, python

Solution

is_vaild != is_valid

Simple typo

Problem

I've been searching for solutions for a whole day and I have almost gone through all the answers on Stackoverflow and still cannot solve my problem. So, I have to raise this question. In models.py, I have: ``` from django.db import models import datetime from django.utils import timezone class Cap(models.Model): title = models.CharField(max_length=50) user_id = models.CharField(max_length=100) dest_id = models.CharField(max_length=100) cap_id = models.CharField(max_length=500) text_part = models.FileField(upload_to='texts/%Y/%m/%d') time_to_live = models.IntegerField() pub_date = models.DateField() def __unicode__(self): return self.title ``` Then in forms.py, I have: ``` from django.forms import ModelForm from latercap.models import Capsule class CapForm(ModelForm): class Meta: model = Cap fields = '__all__' ``` Then in views.py, I have: ``` from django.shortcuts import render from django.http import HttpResponseRedirect from myapp.forms import CapForm def upload(request): # Handle file upload if request.method == 'POST': form = CapForm(request.POST, request.FILES) if form.is_vaild(): form.save() # Redirect to the upload page after POST return HttpResponseRedirect('/myapp/upload/') else: form = CapForm() # An empty, unbound form message = "You can upload your message here!" context = {'message': message, 'form': form} # Render upload page with the documents and the form return render(request, 'myapp/upload.html', context) ``` Then in upload.html, I have: ``` <b>{{message}}</b> <form action="{% url 'myapp:upload' %}" method="post" enctype="multipart/form-data"> {% csrf_token %} <p>{{ form.non_field_errors }}</p> <p>Title: {{ form.title }}</p> <p>From: {{ form.user_id }}</p> <p>To: {{ form.dest_id }}</p> <p>No. {{ form.cap_id }}</p> <p>Open after: {{ form.time_to_live }}</p> <p>Publish date: {{ form.pub_date }}</p> <p>My message:</p> <p> {{ form.text_part }} </p> <p><input type="submit" value="Upload" /></p> </form> ``` When I set correct values into the form and click "Upload" button, I ALWAYS get: ``` > AttributeError at /myapp/upload/ 'CapForm' object has no attribute > 'is_vaild' > Request Method: POST Request > URL: http://127.0.0.1:8000/myapp/upload/ > Django Version: 1.6.5 > Exception Type: AttributeError Exception Value: 'CapForm' object > has no attribute 'is_vaild' ``` I have tried: - `print form.errors`, but nothing was shown - `print form.is_valid()` before the `if`, still gives the error - delete the `text_part` and only pass `request.POST` to the `form`, still gives errors - use `form(data=request.POST, files=request.FILES)`, still errors - `print form.is_multipart()` give me a `True` result - submit an empty or correctly filled form all give the same error What should I do to get this work? Many many thanks!

Original source