質問編集履歴

2

書式の変更

2021/08/27 13:32

投稿

chko16
chko16

スコア3

test CHANGED
File without changes
test CHANGED
@@ -108,41 +108,29 @@
108
108
 
109
109
  def get_client_ip(request):
110
110
 
111
- forwarded_addresses = request.META.get('HTTP_X_FORWARDED_FOR')
111
+ if request.method == 'POST':
112
112
 
113
- if forwarded_addresses:
113
+ form = CommentForm(request.POST or None)
114
114
 
115
+ if form.is_valid():
116
+
117
+ comment = form.save(commit=False)
118
+
115
- ip = forwarded_addresses.split(',')[0]
119
+ comment.ip_address = request.META.get('REMOTE_ADDR')
120
+
121
+ comment.save()
122
+
123
+ return redirect('template_name')
116
124
 
117
125
  else:
118
126
 
119
- ip = request.META.get('REMOTE_ADDR')
120
-
121
-
122
-
123
- if request.method == 'POST':
124
-
125
- form = CommentForm(request.POST or None)
126
-
127
- if form.is_valid():
128
-
129
- comment = form.save(commit=False)
130
-
131
- comment.ip_address = ip
132
-
133
- comment.save()
134
-
135
- return redirect('template_name')
136
-
137
- else:
138
-
139
- form = CommentForm()
127
+ form = CommentForm()
140
128
 
141
129
 
142
130
 
143
131
  context = {
144
132
 
145
- 'form': form
133
+ 'form': form
146
134
 
147
135
  }
148
136
 

1

タイトルの変更

2021/08/27 13:32

投稿

chko16
chko16

スコア3

test CHANGED
@@ -1 +1 @@
1
- Django IPアドレスをデータベースに保存する方法について
1
+ Python Django IPアドレスをデータベースに保存する方法について
test CHANGED
File without changes