「動かして学ぶ python django開発入門」という本に沿ってDjangoについて学習しているのですが、
本番環境に配置した後、問い合わせやサインアップなど試してみたところ「想定外のエラーが発生しました。」となってしまい問い合わせの送信や会員登録ができません...orz
django.logに下記エラーメッセージ出ていたので「admin@example.com」からSESの認証しているアドレスに書き換えたのちに再度ブラウザから試したのですが、アドレス変更前のエラーと変わらない状態です。アドレス書き換えた後に反映させるための作業などあるのでしょうか?
確認するための情報などありましたら随時連携しますので、どなたかご教授いただけないでしょうか。
django.log
2020-03-18 00:25:49,645 [ERROR] /home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/utils/log.py(Line:228) Internal Server Error: /inquiry/ Traceback (most recent call last): File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/handlers/exception.py", line 34, in inner response = get_response(request) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/handlers/base.py", line 115, in _get_response response = self.process_exception_by_middleware(e, request) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/handlers/base.py", line 113, in _get_response response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/generic/base.py", line 71, in view return self.dispatch(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/generic/base.py", line 97, in dispatch return handler(request, *args, **kwargs) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/views/generic/edit.py", line 142, in post return self.form_valid(form) File "/home/app_admin/venv_private_diary/private_diary/diary/views.py", line 23, in form_valid form.send_email() File "/home/app_admin/venv_private_diary/private_diary/diary/forms.py", line 44, in send_email message = EmailMessage(subject=subject, body=message, from_email=from_email, to=to_list, cc=cc_list) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django/core/mail/message.py", line 276, in send return self.get_connection(fail_silently).send_messages([self]) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/django_ses/__init__.py", line 202, in send_messages dkim_headers=self.dkim_headers) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/boto/ses/connection.py", line 323, in send_raw_email return self._make_request('SendRawEmail', params) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/boto/ses/connection.py", line 119, in _make_request self._handle_error(response, body) File "/home/app_admin/venv_private_diary/lib64/python3.7/site-packages/boto/ses/connection.py", line 177, in _handle_error raise ExceptionToRaise(response.status, exc_reason, body) boto.ses.exceptions.SESAddressNotVerifiedError: SESAddressNotVerifiedError: 400 Email address is not verified. <ErrorResponse xmlns="http://ses.amazonaws.com/doc/2010-12-01/"> <Error> <Type>Sender</Type> <Code>MessageRejected</Code> <Message>Email address is not verified. The following identities failed the check in region US-EAST-1: admin@example.com</Message> </Error> <RequestId>3d3dd43b-119e-49b3-9c03-f7000da0f44b</RequestId> </ErrorResponse>
追記1
・下記問合せの部分です。
▼view.py
Python
1class InquiryView(generic.FormView): 2 template_name = "inquiry.html" 3 form_class = InquiryForm 4 success_url = reverse_lazy('diary:inquiry') 5 6 def form_valid(self, form): 7 form.send_email() 8 messages.success(self.request, 'メッセージを送信しました。') 9 logger.info('Inquiry sent by {}'.format(form.cleaned_data['name'])) 10 return super().form_valid(form)
▼forms.py
Python
1from django import forms 2from django.core.mail import EmailMessage 3from .models import Diary 4 5class InquiryForm(forms.Form): 6 name = forms.CharField(label='お名前', max_length=30) 7 email = forms.EmailField(label='メールアドレス') 8 title = forms.CharField(label='タイトル', max_length=30) 9 message = forms.CharField(label='メッセージ', widget=forms.Textarea) 10 11 def __init__(self, *args, **kwargs): 12 super().__init__(*args, **kwargs) 13 14 self.fields['name'].widget.attrs['class'] = 'form-control col-9' 15 self.fields['name'].widget.attrs['placeholder'] = 'お名前をここに入力してください。' 16 17 self.fields['email'].widget.attrs['class'] = 'form-control col-11' 18 self.fields['email'].widget.attrs['placeholder'] = 'メールアドレスをここに入力してください。' 19 20 self.fields['title'].widget.attrs['class'] = 'form-control col-11' 21 self.fields['title'].widget.attrs['placeholder'] = 'タイトルをここに入力してください。' 22 23 self.fields['message'].widget.attrs['class'] = 'form-control col-12' 24 self.fields['message'].widget.attrs['placeholder'] = 'メッセージをここに入力してください。' 25 26 def send_email(self): 27 name = self.cleaned_data['name'] 28 email = self.cleaned_data['email'] 29 title = self.cleaned_data['title'] 30 message = self.cleaned_data['message'] 31 32 subject = 'お問い合わせ {}'.format(title) 33 message = '送信者: {0}\nメールアドレス: {1}\nメッセージ: \n{2}'.format(name, email, message) 34 from_email = 'admin@example.com' 35 to_list = [ 36 'teset@exmple.com' 37 ] 38 cc_list = [ 39 email 40 ] 41 42 message = EmailMessage(subject=subject, body=message, from_email=from_email, to=to_list, cc=cc_list) 43 message.send() 44 45class DiaryCreateForm(forms.ModelForm): 46 class Meta: 47 model = Diary 48 fields = ('title', 'content', 'photo1', 'photo2', 'photo3',) 49 50 def __init__(self, *args, **kwargs): 51 super().__init__(*args, **kwargs) 52 for field in self.fields.values(): 53 field.widget.attrs['class'] = 'form-control'
回答1件
あなたの回答
tips
プレビュー