2014-12-09 4 views
-2

Я новичок в django. Я попытался создать простую форму для электронной почты с простой проверкой. У меня ошибка, я не мог решить. не forms.py и views.py находятся в том же самом каталоге (без внутренних приложений внутри проекта)Python/Django - объект 'unicode' не имеет атрибута 'spilled'

forms.py

from django import forms 

class ContactForm(forms.Form): 
    subject = forms.CharField(max_length=100) 
    email = forms.EmailField(label='Your e-mail address') 
    message = forms.CharField(widget=forms.Textarea) 

def clean_message(self): 
    new_message = self.cleaned_data['message'] 
    num_words = len(new_message.spilt(' ')) 
    if num_words < 4: 
     raise forms.ValidationError('Not enough words!') 
    return new_message 

views.py

from django.shortcuts import render, render_to_response 
from django.http import HttpResponseRedirect 
from django.core.mail import send_mail 
from forms import ContactForm 

def contact(request): 
    if request.method == 'POST': 
     form = ContactForm(request.POST) 
     if form.is_valid(): 
      cd = form.cleaned_data 
      send_mail(
       cd['subject'], 
       cd['message'], 
       cd.get('email', '[email protected]'), 
       ['[email protected]'], 
      ) 
      return HttpResponseRedirect('/contact/thankyou/') 
    else: 
     form = ContactForm() 
    return render(request, 'gadi_templates/contact.html', {'form': form}) 

def thankyou(request): 
    return render_to_response('gadi_templates/thankyou.html') 

моя ошибка:

AttributeError at /contact/ 
'unicode' object has no attribute 'spilt' 
Request Method: POST 
Request URL: http://127.0.0.1:8000/contact/ 
Django Version: 1.7.1 
Exception Type: AttributeError 
Exception Value:  
'unicode' object has no attribute 'spilt' 
Exception Location: /Users/alonbond/django_apps/gadi/gadi/forms.py in clean_message, line 10 

любая помощь? благодаря!

ответ

Смежные вопросы