contact.py on yout root dir of django project ======== from django import forms from django.utils import simplejson from django.http import HttpResponse from django.core.mail import EmailMessage class ContactForm(forms.Form): name = forms.CharField(help_text="Your name...") email = forms.EmailField(help_text="Your email ...",required=True) message = forms.CharField(widget=forms.Textarea,required=True) def sendform(request): form = ContactForm(request.POST) if request.POST and form.is_valid(): message = {'successMessage':"Yeap it send!"} data = form.cleaned_data email_body = " Name %s < %s >\n Message \n %s " %( data['name'], data['email'], data['message'] ) email = EmailMessage( 'contact from %s' % data['name'], email_body, to=['tuemail@gmail.com'], ) email.send() else: message = { 'errorMessage':'Error!!!!', 'execute': "$('form').innerHTML='%s
'; " % form.as_table().replace('\n','') } return HttpResponse( simplejson.dumps(message), mimetype='text/plain' ) contact.html on your root dir template ====
Send a Message {{ f }}
add it to startproject url.py ===== from yourproject.contact import ContactForm urlpatterns = blah blah blah (r'^contacto/$', 'django.views.generic.simple.direct_to_template', {'template':'contact.html','extra_context':{'f':ContactForm()}} ), (r'^contacto/sendform/$','yourproject.contact.sendform' ),