working example of django.contrib.localflavor ?

445 Aufrufe
Direkt zur ersten ungelesenen Nachricht

e

ungelesen,
14.04.2008, 11:58:2614.04.08
an 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

ungelesen,
14.04.2008, 14:10:2014.04.08
an 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

ungelesen,
15.04.2008, 14:19:4715.04.08
an 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

ungelesen,
15.04.2008, 14:33:2615.04.08
an 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
 
Allen antworten
Antwort an Autor
Weiterleiten
0 neue Nachrichten