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

質問編集履歴

3

changed code

2022/12/30 14:30

投稿

alizona
alizona

スコア126

title CHANGED
File without changes
body CHANGED
@@ -10,40 +10,29 @@
10
10
  post = Post.objects.get(pk=pk)
11
11
  if request.method == 'POST':
12
12
  form = CommentForm(request.POST, request.FILES)
13
-
14
- comment=form.save(commit=False)
15
- comment.post=post
16
13
 
17
- if 'image' in request.FILES:
14
+ if form.is_valid():
18
- # comment.image=request.FILES.get('image')
15
+ comment=form.save(commit=False)
19
- # comment.save()
16
+ comment.post=post
20
- image=request.FILES['image']
21
- result = cloudinary.uploader.upload(image)
22
- image_url = result['url']
23
- form.cleaned_data['image'] = image_url
24
17
 
18
+ if 'image' in request.FILES:
19
+ image=request.FILES['image']
20
+ result = cloudinary.uploader.upload(image)
21
+ image_url = result['url']
22
+ form.cleaned_data['image'] = image_url
25
23
 
26
- if 'video' in request.FILES:
24
+ if 'video' in request.FILES:
27
- # form = CommentForm(request.POST, request.FILES)
28
- video = request.FILES['video']
25
+ video = request.FILES['video']
29
- result = cloudinary.uploader.upload_large(video)
26
+ result = cloudinary.uploader.upload_large(video)
30
- video_url = result['url']
27
+ video_url = result['url']
31
- form.cleaned_data['video'] = video_url
28
+ form.cleaned_data['video'] = video_url
32
-
33
-
34
- if form.is_valid():
35
- print('comment.save()')
36
- # comment.save()
37
-
38
29
  form.save()
39
-
40
30
  else:
41
31
  form = CommentForm()
42
32
 
43
33
  return render(request, "registration/post_detail.html",{"post":post, "form":form})
44
34
 
45
35
 
46
-
47
36
  ```
48
37
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-12-30/a7cb5195-390c-40fe-91ef-7ed036718c0c.png)
49
38
 

2

gaz

2022/12/30 14:07

投稿

alizona
alizona

スコア126

title CHANGED
File without changes
body CHANGED
@@ -45,6 +45,6 @@
45
45
 
46
46
 
47
47
  ```
48
+ ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-12-30/a7cb5195-390c-40fe-91ef-7ed036718c0c.png)
48
49
 
49
-
50
50
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-12-30/37a5e41d-cf49-4992-a8bf-a7f393ef45fd.png)

1

画像の変更

2022/12/30 14:06

投稿

alizona
alizona

スコア126

title CHANGED
File without changes
body CHANGED
@@ -46,5 +46,5 @@
46
46
 
47
47
  ```
48
48
 
49
- ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-12-30/c2c06f53-2a1b-4c35-acab-6cea8698fb3d.png)
49
+
50
50
  ![イメージ説明](https://ddjkaamml8q8x.cloudfront.net/questions/2022-12-30/37a5e41d-cf49-4992-a8bf-a7f393ef45fd.png)