Saturday, May 12, 2012

Re: Can't get a Chapter 7 example to work.

Glad you solved it :)

Cheers

On Sun, May 13, 2012 at 4:07 AM, django-user59 <venkat.rangan@gmail.com> wrote:
Found the problem!

The urls.py was set incorrectly -

changed from:

    url(r'^contact/$', 'demoapp.contact.views.ContactForm'),

to:

    url(r'^contact/$', 'demoapp.contact.views.contact'),

and that makes it work.

Thanks - your hint that the object was not a HttpResponse was important one to pursue.


On Saturday, May 12, 2012 8:07:52 AM UTC-7, django-user59 wrote:
Yati,

Thanks so much for a fast response.

Here is my views.py code - I thought I'm returning an instance of HttpResponse.

from django.http import HttpResponseRedirect
from django.core.mail import send_mail
from django.shortcuts import render_to_response
from demoapp.contact.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', 'xyz@example.com'),
                ['xyz@example.com'],
            )
            return HttpResponseRedirect('/contact/thanks/')
    else:
        form = ContactForm(initial={'subject': 'I love your site'})
    return render_to_response('contact_form.html', {'form': form})



On Saturday, May 12, 2012 8:01:57 AM UTC-7, yati sagade wrote:
My wild guess is that you're returning an instance of ContactForm in one of your views. A view should return an HttpResponse object. Check your view that uses this form

On Sat, May 12, 2012 at 8:21 PM, django-user59  wrote:
Hi,

I could not get the Chapter 7 "contact" form example to work. The
public copy-paste is here: http://dpaste.com/747112/copy/

The message I get is:

AttributeError at /contact/
'ContactForm' object has no attribute 'status_code'

My ContactForm definition is as follows:

from django import forms

class ContactForm(forms.Form):
   subject = forms.CharField(max_length=100)
   email = forms.EmailField(required=False, label='Your e-mail
address')
   message = forms.CharField(widget=forms.Textarea)
   def clean_message(self):
       message = self.cleaned_data['message']
       num_words = len(message.split())
       if num_words < 4:
           raise forms.ValidationError("Not enough words!")
       return message

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.




--
Yati Sagade

Twitter: @yati_itay

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To view this discussion on the web visit https://groups.google.com/d/msg/django-users/-/IKBfOVtf7m0J.

To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.



--
Yati Sagade

Twitter: @yati_itay

Organizing member of TEDx EasternMetropolitanBypass
http://www.ted.com/tedx/events/4933
https://www.facebook.com/pages/TEDx-EasternMetropolitanBypass/337763226244869


--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate