2016-09-29 14 views
1

電話番号フィールドを含むDjangoフォームを作成しています。私はどのようにそれを行うかを理解するためにこれらの2つの質問に言及してきました:12。私は、このフォームフィールドを作成しました:Django電話番号フォームフィールドでエラーを取得する

class ContactForm(forms.Form): 
    phone = forms.RegexField(
     regex = r'^\+?[1-9]\d{1,14}$', 
     #regex = r'\+?\d{10,14}$', 
     error_messages = {'required', 'Phone number required'}, 
     widget = forms.TextInput(attrs={'class': 'form-control'}) 
    ) 

私は私のテンプレートでフィールドを表示:

<div> 
    <label for="id_phone">Your Phone Number</label> 
    {{ form.phone.errors }} 
    {{ form.phone }} 
</div> 

私は正規表現が何をしているかを理解し、彼らは私に正しい見えます。しかし、どちらか1つを使用するとこのエラーが発生します。

ValueError at /business/contact/ 
dictionary update sequence element #0 has length 8; 2 is required 
... 
Exception Location: /srv/http/example.com/venvs/dev/local/lib/python2.7/site-packages/django/forms/fields.py in __init__, line 125 
(stacktrace...) 
widget = forms.TextInput(attrs={'class': 'form-control'}) 
super(RegexField, self).__init__(max_length, min_length, *args, **kwargs) 
super(CharField, self).__init__(*args, **kwargs) 
messages.update(error_messages or {}) 
(end of stacktrace) 

このエラーの原因は誰にも分かりますか?それは正規表現によって引き起こされたようです。

答えて

2

私はちょうどそのエラーを発見しました。 ":":

error_messages = {'required': 'Phone number required'}, 

error_messages = {'required', 'Phone number required'}, 

が、私は "" で置き換えるために必要な:それは、この行にあります

関連する問題