質問編集履歴
2
表記ミスの編集
test
CHANGED
File without changes
|
test
CHANGED
@@ -130,6 +130,12 @@
|
|
130
130
|
|
131
131
|
|
132
132
|
|
133
|
+
|
134
|
+
|
135
|
+
▼forms.py
|
136
|
+
|
137
|
+
```Python
|
138
|
+
|
133
139
|
from django import forms
|
134
140
|
|
135
141
|
from django.core.mail import EmailMessage
|
@@ -138,12 +144,6 @@
|
|
138
144
|
|
139
145
|
|
140
146
|
|
141
|
-
|
142
|
-
|
143
|
-
▼forms.py
|
144
|
-
|
145
|
-
```Python
|
146
|
-
|
147
147
|
class InquiryForm(forms.Form):
|
148
148
|
|
149
149
|
name = forms.CharField(label='お名前', max_length=30)
|
1
コードの追加
test
CHANGED
File without changes
|
test
CHANGED
@@ -89,3 +89,157 @@
|
|
89
89
|
</ErrorResponse>
|
90
90
|
|
91
91
|
```
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
|
98
|
+
|
99
|
+
追記1
|
100
|
+
|
101
|
+
・下記問合せの部分です。
|
102
|
+
|
103
|
+
|
104
|
+
|
105
|
+
▼view.py
|
106
|
+
|
107
|
+
```Python
|
108
|
+
|
109
|
+
class InquiryView(generic.FormView):
|
110
|
+
|
111
|
+
template_name = "inquiry.html"
|
112
|
+
|
113
|
+
form_class = InquiryForm
|
114
|
+
|
115
|
+
success_url = reverse_lazy('diary:inquiry')
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
def form_valid(self, form):
|
120
|
+
|
121
|
+
form.send_email()
|
122
|
+
|
123
|
+
messages.success(self.request, 'メッセージを送信しました。')
|
124
|
+
|
125
|
+
logger.info('Inquiry sent by {}'.format(form.cleaned_data['name']))
|
126
|
+
|
127
|
+
return super().form_valid(form)
|
128
|
+
|
129
|
+
```
|
130
|
+
|
131
|
+
|
132
|
+
|
133
|
+
from django import forms
|
134
|
+
|
135
|
+
from django.core.mail import EmailMessage
|
136
|
+
|
137
|
+
from .models import Diary
|
138
|
+
|
139
|
+
|
140
|
+
|
141
|
+
|
142
|
+
|
143
|
+
▼forms.py
|
144
|
+
|
145
|
+
```Python
|
146
|
+
|
147
|
+
class InquiryForm(forms.Form):
|
148
|
+
|
149
|
+
name = forms.CharField(label='お名前', max_length=30)
|
150
|
+
|
151
|
+
email = forms.EmailField(label='メールアドレス')
|
152
|
+
|
153
|
+
title = forms.CharField(label='タイトル', max_length=30)
|
154
|
+
|
155
|
+
message = forms.CharField(label='メッセージ', widget=forms.Textarea)
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
def __init__(self, *args, **kwargs):
|
160
|
+
|
161
|
+
super().__init__(*args, **kwargs)
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
self.fields['name'].widget.attrs['class'] = 'form-control col-9'
|
166
|
+
|
167
|
+
self.fields['name'].widget.attrs['placeholder'] = 'お名前をここに入力してください。'
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
self.fields['email'].widget.attrs['class'] = 'form-control col-11'
|
172
|
+
|
173
|
+
self.fields['email'].widget.attrs['placeholder'] = 'メールアドレスをここに入力してください。'
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
self.fields['title'].widget.attrs['class'] = 'form-control col-11'
|
178
|
+
|
179
|
+
self.fields['title'].widget.attrs['placeholder'] = 'タイトルをここに入力してください。'
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
self.fields['message'].widget.attrs['class'] = 'form-control col-12'
|
184
|
+
|
185
|
+
self.fields['message'].widget.attrs['placeholder'] = 'メッセージをここに入力してください。'
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
def send_email(self):
|
190
|
+
|
191
|
+
name = self.cleaned_data['name']
|
192
|
+
|
193
|
+
email = self.cleaned_data['email']
|
194
|
+
|
195
|
+
title = self.cleaned_data['title']
|
196
|
+
|
197
|
+
message = self.cleaned_data['message']
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
subject = 'お問い合わせ {}'.format(title)
|
202
|
+
|
203
|
+
message = '送信者: {0}\nメールアドレス: {1}\nメッセージ: \n{2}'.format(name, email, message)
|
204
|
+
|
205
|
+
from_email = 'admin@example.com'
|
206
|
+
|
207
|
+
to_list = [
|
208
|
+
|
209
|
+
'teset@exmple.com'
|
210
|
+
|
211
|
+
]
|
212
|
+
|
213
|
+
cc_list = [
|
214
|
+
|
215
|
+
email
|
216
|
+
|
217
|
+
]
|
218
|
+
|
219
|
+
|
220
|
+
|
221
|
+
message = EmailMessage(subject=subject, body=message, from_email=from_email, to=to_list, cc=cc_list)
|
222
|
+
|
223
|
+
message.send()
|
224
|
+
|
225
|
+
|
226
|
+
|
227
|
+
class DiaryCreateForm(forms.ModelForm):
|
228
|
+
|
229
|
+
class Meta:
|
230
|
+
|
231
|
+
model = Diary
|
232
|
+
|
233
|
+
fields = ('title', 'content', 'photo1', 'photo2', 'photo3',)
|
234
|
+
|
235
|
+
|
236
|
+
|
237
|
+
def __init__(self, *args, **kwargs):
|
238
|
+
|
239
|
+
super().__init__(*args, **kwargs)
|
240
|
+
|
241
|
+
for field in self.fields.values():
|
242
|
+
|
243
|
+
field.widget.attrs['class'] = 'form-control'
|
244
|
+
|
245
|
+
```
|