working example of django.contrib.localflavor ?

444 views
Skip to first unread message

e

unread,
Apr 14, 2008, 11:58:26 AM4/14/08
to Django users
I have a form set up and all working, its basically straight out of
the Form Processing chapter of the django book:

class ContactForm(forms.Form):
email = forms.EmailField(required=True)
message = forms.CharField()
phone_number = forms.CharField()

def contact(request):
form = ContactForm()
return render_to_response('contact.html', {'form': form})

Now this works just fine, but I want to use
django.contrib.localflavor.us.forms.USPhoneNumberFIeld instead of the
CharField for the phone_number. When I replace it with this line:

phone_number = us.forms.USPhoneNumberField(max_length=100)

I get this error:

ViewDoesNotExist: Tried contact in module mysite.contact.views. Error
was: 'module' object has no attribute 'forms'

What am I doing wrong?

Karen Tracey

unread,
Apr 14, 2008, 2:10:20 PM4/14/08
to django...@googlegroups.com

I'm assuming you have:

from django.contrib.localflavor import us

somewhere before you try to define phone_number as us.forms.USPhone...

Instead try:

from django.contrib.localflavor.us.forms import USPhoneNumberField
phone_number = USPhoneNumberField()

This works for me.  I don't know why the documentation (http://www.djangoproject.com/documentation/localflavor/) shows an example using the first kind of import, since it does not appear that things are set up for that to work.

Karen

e

unread,
Apr 15, 2008, 2:19:47 PM4/15/08
to Django users
Is this worthy of submitting a ticket to fix the documentation for?

On Apr 14, 2:10 pm, "Karen Tracey" <kmtra...@gmail.com> wrote:

Karen Tracey

unread,
Apr 15, 2008, 2:33:26 PM4/15/08
to django...@googlegroups.com
On Tue, Apr 15, 2008 at 2:19 PM, e <eric...@gmail.com> wrote:
Is this worthy of submitting a ticket to fix the documentation for?

I'd say so.  Near as I can tell if you cut & paste the example from the documentation it doesn't work.  That seems wrong, and worth fixing. 

Karen
 
Reply all
Reply to author
Forward
0 new messages