def contact(request):
if request.method == 'POST':
#checks if the request method was a post, i.e. if the form has been
submitted
#and initializes the form with the data that was submitted
form = ContactForm(request.POST)
if form.is_valid():
#if form validation passed, do your assigments and extract data
from the form data
asunto = form.cleaned_data['asunto']
recado = form.cleaned_data['recado']
email = form.cleaned_data['email']
ccopia = form.cleaned_data['ccopia']
from django.core.mail import send_mail
send_mail(subject, mensaje, email, '[email protected]')
return HttpResponseRedirect('/gracias/')
else:
#this is where your problem is. The indent on this line MUST match the if
for the request.method == 'POST'
form = ContactForm(initial={'subject': 'Me agrada su sitio!'})
#this indent below MUST also match the indent for the request.method
meaning that it
return render(request, 'contacto_form.html', {'form': form,})
so that with any condition based on the request method, form will always be
set.
Hope you got it ?
On Tuesday, 5 March 2013 04:05:26 UTC+1, Ana Molf wrote:
>
> I can¡t solve the follow error
>
> def contact(request):
> if request.method == 'POST':
> form = ContactForm(request.POST)
> if form.is_valid():
> asunto = form.cleaned_data['asunto']
> recado = form.cleaned_data['recado']
> email = form.cleaned_data['email']
> ccopia = form.cleaned_data['ccopia']
> from django.core.mail import send_mail
> send_mail(subject, mensaje, email,
> '[email protected]<javascript:>
> ')
> return HttpResponseRedirect('/gracias/')
> else:
> form = ContactForm(
> initial={'subject': 'Me agrada su sitio!'}
> )
> return render(request, 'contacto_form.html', {
> 'form': form,
> })
>
> line 89
>
>
> from django.core.mail import send_mail
> ^
> IndentationError: unindent does not match any outer indentation level
>
>
> Book code is not working https://docs.djangoproject.com/en/dev/topics/forms/
>
> Thanks for any comment
>
> Django 1.4.4
> 'Apache/2.2.16 (Debian)'
>
>
>
--
You received this message because you are subscribed to the Google Groups
"Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-users?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.