简体   繁体   中英

Unable to get value (email) from dictionary in Python/Django

OrderedDict([('first_name', <django.forms.fields.CharField object at 0x7f9b5bed4c50>), ('last_name', <django.forms.fields.CharField object at 0x7f9b3b7abf50>), ('email', <django.forms.fields.EmailField object at 0x7f9b3b7abf10>)])

I am a new programmer in Python/Django, and I neeed a bit a of help.

I have this dictionnary, when I called self.fields . I am trying to get access the value of email with email = self.fields.get('email', False) , which is supposed to be something like test@test.com , but I got <django.forms.fields.EmailField object at 0x7f9b3b7abf10> . Is it because the space is not used yet? Otherwise, how could I get the value of email ?

The correct way to get data from a form is to first call .is_valid() , then look up the value in self.cleaned_data , in this case, you'd do:

if self.is_valid():
    email = self.cleaned_data['email']

For more information, see the docs .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM