teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

4

base.htmlの追加、投稿の整理、view.py、form.pyの削除

2020/03/24 05:51

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -3,78 +3,7 @@
3
3
  そのまま実装しています。現在開発中で、HPのお問い合わせから送信されたものをPycharmに送信するまでを目指しています。
4
4
  HTML,CSSともに間違いはなく、ローカルホストからHPを開くことが可能です。さらにお問い合わせ画面にも移ります。そこで文字を打ち、送信を押すのですが、送信画面に変化はなくPycharmに反映されることはありません。これはいったい何が問題だと考えられますか?
5
5
 
6
- ### __forms.py__
7
- ```python
8
- from django import forms
9
- from django.core.mail import EmailMessage
10
6
 
11
-
12
- class InquiryForm(forms.Form):
13
- name = forms.CharField(label='name', max_length=30)
14
- email = forms.EmailField(label='email address')
15
- title = forms.CharField(label='title', max_length=40)
16
- message = forms.CharField(label='message', widget=forms.Textarea)
17
-
18
- def __init__(self, *args, **kwargs):
19
- super().__init__(*args, **kwargs)
20
-
21
- self.fields['name'].widget.attrs['class'] = 'form-control col-9'
22
- self.fields['name'].widget.attrs['placeholder'] = 'input your name'
23
- self.fields['email'].widget.attrs['class'] = 'form-control col-11'
24
- self.fields['email'].widget.attrs['placeholder'] = 'fill in your email address'
25
- self.fields['title'].widget.attrs['class'] = 'form-control col-11'
26
- self.fields['title'].widget.attrs['placeholder'] = 'fill in the title'
27
- self.fields['message'].widget.attrs['class'] = 'form-control col-12'
28
- self.fields['message'].widget.attrs['placeholder'] = 'fill in your message'
29
-
30
- def send_email(self):
31
- name = self.cleaned_data['name']
32
- email = self.cleaned_data['email']
33
- title = self.cleaned_data['title']
34
- message = self.cleaned_data['message']
35
-
36
- subject = 'Inquiry {}'.format(title)
37
- message = 'Mail sender: {0}\nMail address: {1}\nMessage:\n{2}'.format(name, email, message)
38
- from_email = 'admin@example.com'
39
- to_list = [
40
- 'test@example.com'
41
- ]
42
- cc_list = [
43
- email
44
- ]
45
-
46
- message = EmailMessage(subject=subject, body=message, from_email=from_email, to=to_list, cc=cc_list)
47
- message.send()
48
-
49
- ```
50
- ### __views.py__
51
- ```python
52
- from django.shortcuts import render
53
- import logging
54
- from django.urls import reverse_lazy
55
- from django.views import generic
56
- from .forms import InquiryForm
57
-
58
- # Create your views here.
59
-
60
- logger = logging.getLogger(__name__)
61
-
62
-
63
- class IndexView(generic.TemplateView):
64
- template_name = "index.html"
65
-
66
-
67
- class InquiryView(generic.FormView):
68
- template_name = "inquiry.html"
69
- form_class = InquiryForm
70
- success_url = reverse_lazy('diary:inquiry')
71
-
72
- def form_valid(self, form):
73
- form.send_email()
74
- logger.info('Inquiry sent by {}'.format(form.cleaned_data['name']))
75
- return super().form_valid(form)
76
- ```
77
-
78
7
  ### __settings.py__
79
8
  ```python
80
9
  from japweb.settings_common import *
@@ -123,8 +52,83 @@
123
52
 
124
53
  ```
125
54
 
126
- ### 追記(テンプレートファイル
55
+ ### 追記(Base.html
56
+ ```HTML
57
+ {% load static %}
58
+ <html lang="ja">
59
+ <head>
60
+ <meta charset="UTF-8">
61
+ <meta name="viewport" content="width=device-width,initial-scale=1,shrink-to-fit=no">
62
+ <meta name="descripition" content="">
63
+ <meta name="author" content="">
64
+
65
+ <title>{% block title %}{% endblock%}</title>
66
+
67
+ <!--Bootstrap core CSS-->
68
+ <link href="{% static 'vendor/bootstrap/css/bootstrap.min.css' %}" rel="stylesheet">
69
+
70
+ <!--Custom fonts for this template-->
71
+ <link href="https://fonts.googleapis.com/css?family=Catamaran:100,200,300,400,500,600,700,800,900" rel="stylesheet">
72
+ <link href="https://fonts.googleapis.com/css?family=Lato:100,100i,300,300i,400,400i,700,700i,900,900i" rel="stylesheet">
73
+
74
+ <!--Custom styles for this template-->
75
+ <link href="{% static 'css/one-page-wonder.min.css' %}" rel="stylesheet">
76
+
77
+ <!--My style-->
78
+ <link rel="stylesheet" type="text/css" href="{% static 'css/mystyle.css' %}">
79
+ {% block head %}{% endblock %}
80
+ </head>
81
+
82
+ <body>
83
+
84
+ <div id="wrapper">
85
+ <!-- Navigation -->
86
+ <nav class="navbar navbar-expand-lg navbar-dark navbar-custom fixed-top">
87
+ <div class="container">
88
+ <a class="navbar-brand" href="{% url 'diary:index' %}">Squeeze Japanese</a>
89
+ <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarResponsive" aria-controls="navbarResponsive" aria-expanded="false" aria-label="Toggle navigation">
90
+ <span class="navbar-toggler-icon"></span>
91
+ </button>
92
+ <div class="collapse navbar-collapse" id="navbarResponsive">
93
+ <ul class="navbar-nav mr-auto">
94
+ <li class="nav-item {% block active_inquiry %}{% endblock%}">
95
+ <a class="nav-link" href="{% url 'diary:inquiry' %}">INQUIRY</a>
96
+ </li>
97
+ </ul>
98
+ <ul class="navbar-nav ml-auto">
99
+ <li class="nav-item">
100
+ <a class="nav-link" href="#">Sign Up</a>
101
+ </li>
102
+ <li class="nav-item">
103
+ <a class="nav-link" href="#">Log In</a>
104
+ </li>
105
+ </ul>
106
+ </div>
107
+ </div>
108
+ </nav>
109
+
110
+ {% block header %}{% endblock %}
111
+
112
+ {% block contents%}{% endblock%}
113
+
114
+ <!-- Footer -->
115
+ <footer class="py-5 bg-black">
116
+ <div class="container">
117
+ <p class="m-0 text-center text-white small">Copyright &copy; Private Dairy 2020</p>
118
+ </div>
119
+ <!-- /.container -->
120
+ </footer>
121
+
122
+ <!-- Bootstrap core JavaScript -->
123
+ <script src="{% static 'vendor/jquery/jquery.min.js' %}"></script>
124
+ <script src="{% static 'vendor/bootstrap/js/bootstrap.bundle.min.js' %}"></script>
125
+ </div>
126
+ </body>
127
+ </html>
127
128
  ```
129
+
130
+ ### 追記(Inquiry.html)
131
+ ```HTML
128
132
  <!DOCTYPE html>
129
133
  <html lang="ja">
130
134
  <head>
@@ -178,9 +182,8 @@
178
182
  ]
179
183
  ```
180
184
 
181
- ### 追記(最終画像)
182
- ![イメージ説明](b0df9c151084a22f667a3f0cf4df89f2.jpeg)
183
185
 
186
+
184
187
  ### 追記(エラー分)
185
188
  ```Error
186
189
 
@@ -263,4 +266,7 @@
263
266
  simple_server.py", line 35, in close
264
267
  self.status.split(' ',1)[0], self.bytes_sent
265
268
  AttributeError: 'NoneType' object has no attribute 'split'
266
- ```
269
+ ```
270
+
271
+ ### 追記(最終画像)
272
+ ![イメージ説明](b0df9c151084a22f667a3f0cf4df89f2.jpeg)

3

追記ーエラー文

2020/03/24 05:51

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -179,4 +179,88 @@
179
179
  ```
180
180
 
181
181
  ### 追記(最終画像)
182
- ![イメージ説明](b0df9c151084a22f667a3f0cf4df89f2.jpeg)
182
+ ![イメージ説明](b0df9c151084a22f667a3f0cf4df89f2.jpeg)
183
+
184
+ ### 追記(エラー分)
185
+ ```Error
186
+
187
+
188
+ 2020-03-22 21:31:45,167 [WARNING] C:\Users\django\utils\log.py(Line:228) Not Found: /favicon.ico
189
+ 2020-03-22 21:31:45,167 [WARNING] C:\Users\django\core\servers\basehttp.py(Line:157) GET/favicon.ico HTTP/1.1" 404 2304
190
+
191
+ Traceback (most recent call last):
192
+ handlers.py", line 138, in run
193
+ self.finish_response()
194
+ handlers.py", line 180, in finish_response
195
+ self.write(data)
196
+ handlers.py", line 274, in write
197
+ self.send_headers()
198
+ handlers.py", line 332, in send_headers
199
+ self.send_preamble()
200
+ handlers.py", line 255, in send_preamble
201
+ ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
202
+ handlers.py", line 453, in _write
203
+ result = self.stdout.write(data)
204
+ socketserver.py", line 799, in write
205
+ self._sock.sendall(b)
206
+ ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
207
+ 2020-03-22 21:31:45,167 [ERROR] C:\Users\django\core\servers\basehttp.py(Line:157) "GET /favicon.ico HTTP/1.1" 500 59
208
+ ----------------------------------------
209
+ Exception happened during processing of request from ('127.0.0.1', 52275)
210
+ Traceback (most recent call last):
211
+ handlers.py", line 138, in run
212
+ self.finish_response()
213
+ handlers.py", line 180, in finish_response
214
+ self.write(data)
215
+ handlers.py", line 274, in write
216
+ self.send_headers()
217
+ handlers.py", line 332, in send_headers
218
+ self.send_preamble()
219
+ handlers.py", line 255, in send_preamble
220
+ ('Date: %s\r\n' % format_date_time(time.time())).encode('iso-8859-1')
221
+ handlers.py", line 453, in _write
222
+ result = self.stdout.write(data)
223
+ socketserver.py", line 799, in write
224
+ self._sock.sendall(b)
225
+ ConnectionAbortedError: [WinError 10053] An established connection was aborted by the software in your host machine
226
+
227
+ During handling of the above exception, another exception occurred:
228
+
229
+ Traceback (most recent call last):
230
+ handlers.py", line 141, in run
231
+ self.handle_error()
232
+ basehttp.py", line 119, in handle_error
233
+ super().handle_error()
234
+ handlers.py", line 368, in handle_error
235
+ self.finish_response()
236
+ handlers.py", line 180, in finish_response
237
+ self.write(data)
238
+ handlers.py", line 274, in write
239
+ self.send_headers()
240
+ handlers.py", line 331, in send_headers
241
+ if not self.origin_server or self.client_is_modern():
242
+ handlers.py", line 344, in client_is_modern
243
+ return self.environ['SERVER_PROTOCOL'].upper() != 'HTTP/0.9'
244
+ TypeError: 'NoneType' object is not subscriptable
245
+
246
+ During handling of the above exception, another exception occurred:
247
+
248
+ Traceback (most recent call last):
249
+ socketserver.py", line 650, in process_request_thread
250
+ self.finish_request(request, client_address)
251
+ socketserver.py", line 360, in finish_request
252
+ self.RequestHandlerClass(request, client_address, self)
253
+ socketserver.py", line 720, in __init__
254
+ self.handle()
255
+ basehttp.py", line 174, in handle
256
+ self.handle_one_request()
257
+ basehttp.py", line 197, in handle_one_request
258
+ handler.run(self.server.get_app())
259
+ handlers.py", line 144, in run
260
+ self.close()
261
+ basehttp.py", line 114, in close
262
+ super().close()
263
+ simple_server.py", line 35, in close
264
+ self.status.split(' ',1)[0], self.bytes_sent
265
+ AttributeError: 'NoneType' object has no attribute 'split'
266
+ ```

2

追記ー画像

2020/03/22 12:47

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -176,4 +176,7 @@
176
176
  path("", views.IndexView.as_view(), name="index"),
177
177
  path('inquiry/', views.InquiryView.as_view(), name='inquiry'),
178
178
  ]
179
- ```
179
+ ```
180
+
181
+ ### 追記(最終画像)
182
+ ![イメージ説明](b0df9c151084a22f667a3f0cf4df89f2.jpeg)

1

コードの追記です。

2020/03/22 12:18

投稿

退会済みユーザー
title CHANGED
File without changes
body CHANGED
@@ -121,4 +121,59 @@
121
121
 
122
122
  EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend'
123
123
 
124
+ ```
125
+
126
+ ### 追記(テンプレートファイル)
127
+ ```
128
+ <!DOCTYPE html>
129
+ <html lang="ja">
130
+ <head>
131
+ {% extends 'base.html'%}
132
+ <meta charset="UTF-8">
133
+ {% block title %}Inquiry:Private Diary{% endblock %}
134
+ {% block active_inquiry %} active {% endblock %}
135
+
136
+ {% block contents %}
137
+ </head>
138
+ <body>
139
+ <div class="container">
140
+ <div class="row">
141
+ <div class="my-div-style">
142
+ <form method="post">
143
+ {% csrf_token %}
144
+ {{ form.non_field_errors }}
145
+ {% for field in form %}
146
+ <div class="form-group row">
147
+ <label for = "{{ field.id_for_label }}" class ="col-sm-4 col-form-label">
148
+ <strong>{{ field.label_tag }}</strong>
149
+ </label>
150
+ <div class="col-sm-8">
151
+ {{ field }}
152
+ {{ field.errors }}
153
+ </div>
154
+ </div>
155
+ {% endfor %}
156
+
157
+ <div class="offset-sm-4 col-sm-8">
158
+ <buttun class="btn btn-primary" type="submit">submit</buttun>
159
+ </div>
160
+ </form>
161
+ </div>
162
+ </div>
163
+ </div>
164
+ {% endblock %}
165
+ </body>
166
+ </html>
167
+ ```
168
+
169
+ ### 追記(urls.py)
170
+ ```python
171
+ from django.urls import path
172
+ from. import views
173
+
174
+ app_name = 'diary'
175
+ urlpatterns = [
176
+ path("", views.IndexView.as_view(), name="index"),
177
+ path('inquiry/', views.InquiryView.as_view(), name='inquiry'),
178
+ ]
124
179
  ```