質問編集履歴
8
不要部分の削除
title
CHANGED
File without changes
|
body
CHANGED
@@ -19,46 +19,8 @@
|
|
19
19
|
```
|
20
20
|
|
21
21
|
###該当のソースコード
|
22
|
-
post_edit.html
|
23
|
-
```ここに言語を入力
|
24
|
-
{% extends 'posts/base.html' %}
|
25
|
-
{% block content %}
|
26
|
-
<h1>New post</h1>
|
27
|
-
<form method="POST" class="post-form">{% csrf_token %}
|
28
|
-
{{ form.as_p }}
|
29
|
-
<button type="submit" class="save btn btn-default">Save</button>
|
30
|
-
</form>
|
31
|
-
{% endblock %}
|
32
|
-
```
|
33
22
|
views.py
|
34
23
|
```ここに言語を入力
|
35
|
-
from django.shortcuts import render, get_object_or_404, redirect
|
36
|
-
from django.utils import timezone
|
37
|
-
from .models import Post
|
38
|
-
from .forms import PostForm
|
39
|
-
|
40
|
-
|
41
|
-
# Create your views here.
|
42
|
-
def post_list(request):
|
43
|
-
posts = Post.objects.filter(published_date__lte=timezone.now()).order_by('published_date')
|
44
|
-
return render(request, 'posts/post_list.html', {'posts': posts})
|
45
|
-
|
46
|
-
def post_detail(request, pk):
|
47
|
-
post = get_object_or_404(Post, pk=pk)
|
48
|
-
return render(request, 'posts/post_detail.html', {'post': post})
|
49
|
-
|
50
|
-
def post_new(request):
|
51
|
-
if request.method == "POST":
|
52
|
-
form = PostForm(request.POST)
|
53
|
-
if form.is_valid():
|
54
|
-
post = form.save(commit=False)
|
55
|
-
post.author = request.user
|
56
|
-
post.save()
|
57
|
-
return redirect('posts.views.post_detail', pk=post.pk)
|
58
|
-
else:
|
59
|
-
form = PostForm()
|
60
|
-
return render(request, 'posts/post_edit.html', {'form': form})
|
61
|
-
|
62
24
|
def post_edit(request, pk):
|
63
25
|
post = get_object_or_404(Post, pk=pk)
|
64
26
|
if request.method == "POST":
|
@@ -71,86 +33,4 @@
|
|
71
33
|
else:
|
72
34
|
form = PostForm(instance=post)
|
73
35
|
return render(request, 'posts/post_edit.html', {'form': form})
|
74
|
-
```
|
75
|
-
base.html
|
76
|
-
```ここに言語を入力
|
77
|
-
{% load staticfiles %}
|
78
|
-
|
79
|
-
<html>
|
80
|
-
<head>
|
81
|
-
<title>Blog</title>
|
82
|
-
<link href="http://fonts.googleapis.com/css?family=Lobster&subset=latin,latin-ext" rel="stylesheet" type="text/css">
|
83
|
-
</head>
|
84
|
-
<body>
|
85
|
-
<div class="page-header">
|
86
|
-
<h1><a href="/">Blog</a></h1>
|
87
|
-
<input type="button" value="投稿" onClick="location.href='/post/new';">
|
88
|
-
</div>
|
89
|
-
|
90
|
-
<div class="content container">
|
91
|
-
<div class="row">
|
92
|
-
<div class="col-md-8">
|
93
|
-
{% block content %}
|
94
|
-
{% endblock %}
|
95
|
-
</div>
|
96
|
-
</div>
|
97
|
-
</div>
|
98
|
-
</body>
|
99
|
-
</html>
|
100
|
-
```
|
101
|
-
post_detail.html
|
102
|
-
```
|
103
|
-
{% extends 'posts/base.html' %}
|
104
|
-
|
105
|
-
{% block content %}
|
106
|
-
<div class="post">
|
107
|
-
{% if post.published_date %}
|
108
|
-
<div class="date">
|
109
|
-
{{ post.published_date }}
|
110
|
-
</div>
|
111
|
-
{% endif %}
|
112
|
-
<input type="button" value="編集" onClick="location.href='/post/{{ post.id }}/edit';">
|
113
|
-
<h1>{{ post.title }}</h1>
|
114
|
-
<p>{{ post.text|linebreaks }}</p>
|
115
|
-
</div>
|
116
|
-
{% endblock %}
|
117
|
-
|
118
|
-
```
|
119
|
-
###試したこと
|
120
|
-
views.pyの下記のように変えところ、編集ボタンを押しても編集画面へ遷移できなくなってしまいました。
|
121
|
-
](8c58329b07f149e0afa55ac3534bb4bc.png)
|
122
|
-
```ここに言語を入力
|
123
|
-
def post_detail(request, pk):
|
124
|
-
post = get_object_or_404(Post, pk=pk)
|
125
|
-
return render(request, 'posts/post_detail.html', {'post': post})
|
126
|
-
|
127
|
-
def post_edit(request, pk):
|
128
|
-
post = get_object_or_404(Post, pk=pk)
|
129
|
-
if request.method == "POST":
|
130
|
-
form = PostForm(request.POST, instance=post)
|
131
|
-
if form.is_valid():
|
132
|
-
post = form.save(commit=False)
|
133
|
-
post.author = request.user
|
134
|
-
post.save()
|
135
|
-
return redirect('posts.views.post_detail', pk=post.pk)
|
136
|
-
else:
|
137
|
-
form = PostForm(instance=post)
|
138
|
-
return render(request, 'posts/post_edit.html', {'form': form})
|
139
|
-
```
|
140
|
-
```ここに言語を入力
|
141
|
-
def post_detail(request, pk):
|
142
|
-
post = get_object_or_404(Post, pk=pk)
|
143
|
-
return render(request, 'posts/post_detail.html', {'post': post})
|
144
|
-
def post_edit(request, pk):
|
145
|
-
post = get_object_or_404(Post, pk=pk)
|
146
|
-
if request.method == "POST":
|
147
|
-
form = PostForm(request.POST, instance=post)
|
148
|
-
if form.is_valid():
|
149
|
-
post = form.save(commit=False)
|
150
|
-
post.author = request.user
|
151
|
-
post.save()
|
152
|
-
return redirect('posts.views.post_detail', pk=post.pk)
|
153
|
-
else:
|
154
|
-
form = PostForm(instance=post)
|
155
|
-
return redirect('/post/' + str(post.pk) + '/')
|
156
36
|
```
|
7
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -98,11 +98,32 @@
|
|
98
98
|
</body>
|
99
99
|
</html>
|
100
100
|
```
|
101
|
+
post_detail.html
|
102
|
+
```
|
103
|
+
{% extends 'posts/base.html' %}
|
101
104
|
|
105
|
+
{% block content %}
|
106
|
+
<div class="post">
|
107
|
+
{% if post.published_date %}
|
108
|
+
<div class="date">
|
109
|
+
{{ post.published_date }}
|
110
|
+
</div>
|
111
|
+
{% endif %}
|
112
|
+
<input type="button" value="編集" onClick="location.href='/post/{{ post.id }}/edit';">
|
113
|
+
<h1>{{ post.title }}</h1>
|
114
|
+
<p>{{ post.text|linebreaks }}</p>
|
115
|
+
</div>
|
116
|
+
{% endblock %}
|
117
|
+
|
118
|
+
```
|
102
119
|
###試したこと
|
103
120
|
views.pyの下記のように変えところ、編集ボタンを押しても編集画面へ遷移できなくなってしまいました。
|
104
121
|
](8c58329b07f149e0afa55ac3534bb4bc.png)
|
105
122
|
```ここに言語を入力
|
123
|
+
def post_detail(request, pk):
|
124
|
+
post = get_object_or_404(Post, pk=pk)
|
125
|
+
return render(request, 'posts/post_detail.html', {'post': post})
|
126
|
+
|
106
127
|
def post_edit(request, pk):
|
107
128
|
post = get_object_or_404(Post, pk=pk)
|
108
129
|
if request.method == "POST":
|
@@ -117,6 +138,9 @@
|
|
117
138
|
return render(request, 'posts/post_edit.html', {'form': form})
|
118
139
|
```
|
119
140
|
```ここに言語を入力
|
141
|
+
def post_detail(request, pk):
|
142
|
+
post = get_object_or_404(Post, pk=pk)
|
143
|
+
return render(request, 'posts/post_detail.html', {'post': post})
|
120
144
|
def post_edit(request, pk):
|
121
145
|
post = get_object_or_404(Post, pk=pk)
|
122
146
|
if request.method == "POST":
|
6
追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -103,8 +103,30 @@
|
|
103
103
|
views.pyの下記のように変えところ、編集ボタンを押しても編集画面へ遷移できなくなってしまいました。
|
104
104
|
](8c58329b07f149e0afa55ac3534bb4bc.png)
|
105
105
|
```ここに言語を入力
|
106
|
+
def post_edit(request, pk):
|
107
|
+
post = get_object_or_404(Post, pk=pk)
|
108
|
+
if request.method == "POST":
|
109
|
+
form = PostForm(request.POST, instance=post)
|
110
|
+
if form.is_valid():
|
111
|
+
post = form.save(commit=False)
|
112
|
+
post.author = request.user
|
113
|
+
post.save()
|
114
|
+
return redirect('posts.views.post_detail', pk=post.pk)
|
115
|
+
else:
|
116
|
+
form = PostForm(instance=post)
|
106
|
-
return render(request, 'posts/post_edit.html', {'form': form})
|
117
|
+
return render(request, 'posts/post_edit.html', {'form': form})
|
107
118
|
```
|
108
119
|
```ここに言語を入力
|
120
|
+
def post_edit(request, pk):
|
121
|
+
post = get_object_or_404(Post, pk=pk)
|
122
|
+
if request.method == "POST":
|
123
|
+
form = PostForm(request.POST, instance=post)
|
124
|
+
if form.is_valid():
|
125
|
+
post = form.save(commit=False)
|
126
|
+
post.author = request.user
|
127
|
+
post.save()
|
128
|
+
return redirect('posts.views.post_detail', pk=post.pk)
|
129
|
+
else:
|
130
|
+
form = PostForm(instance=post)
|
109
|
-
return redirect('/post/' + str(post.pk) + '/')
|
131
|
+
return redirect('/post/' + str(post.pk) + '/')
|
110
132
|
```
|
5
試したことの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -97,4 +97,14 @@
|
|
97
97
|
</div>
|
98
98
|
</body>
|
99
99
|
</html>
|
100
|
+
```
|
101
|
+
|
102
|
+
###試したこと
|
103
|
+
views.pyの下記のように変えところ、編集ボタンを押しても編集画面へ遷移できなくなってしまいました。
|
104
|
+
](8c58329b07f149e0afa55ac3534bb4bc.png)
|
105
|
+
```ここに言語を入力
|
106
|
+
return render(request, 'posts/post_edit.html', {'form': form})
|
107
|
+
```
|
108
|
+
```ここに言語を入力
|
109
|
+
return redirect('/post/' + str(post.pk) + '/')
|
100
110
|
```
|
4
エラーメッセージの追記
title
CHANGED
File without changes
|
body
CHANGED
@@ -3,8 +3,21 @@
|
|
3
3
|
■ [参照ページ](https://djangogirlsjapan.gitbooks.io/workshop_tutorialjp/content/django_forms/)
|
4
4
|
|
5
5
|
###発生している問題・エラーメッセージ
|
6
|
+
```ここに言語を入力
|
6
|
-
|
7
|
+
Page not found (404)
|
8
|
+
Request Method: GET
|
9
|
+
Request URL: http://127.0.0.1:8000/post/21/edit/posts.views.post_detail
|
7
10
|
|
11
|
+
Using the URLconf defined in blog.urls, Django tried these URL patterns, in this order:
|
12
|
+
^$
|
13
|
+
^post/(?P<pk>[0-9]+)/$
|
14
|
+
^post/new/$ [name='post_new']
|
15
|
+
^post/(?P<pk>[0-9]+)/edit/$
|
16
|
+
^admin/
|
17
|
+
The current URL, post/21/edit/posts.views.post_detail, didn't match any of these.
|
18
|
+
You're seeing this error because you have DEBUG = True in your Django settings file. Change that to False, and Django will display a standard 404 page.
|
19
|
+
```
|
20
|
+
|
8
21
|
###該当のソースコード
|
9
22
|
post_edit.html
|
10
23
|
```ここに言語を入力
|
3
誤字の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -4,8 +4,9 @@
|
|
4
4
|
|
5
5
|
###発生している問題・エラーメッセージ
|
6
6
|

|
7
|
+
|
8
|
+
###該当のソースコード
|
7
9
|
post_edit.html
|
8
|
-
###該当のソースコード
|
9
10
|
```ここに言語を入力
|
10
11
|
{% extends 'posts/base.html' %}
|
11
12
|
{% block content %}
|
2
誤字の修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
-
DjangoGirlsというチュートリアルに従って、Pythonの
|
2
|
+
DjangoGirlsというチュートリアルに従って、PythonのDjangoを使いblogを作成しようとしています。そこで、ブログの投稿ページは作成し、データをデータベースに保存することはできたものの、次の画面に遷移することができずエラーが出てしまいました。
|
3
3
|
■ [参照ページ](https://djangogirlsjapan.gitbooks.io/workshop_tutorialjp/content/django_forms/)
|
4
4
|
|
5
5
|
###発生している問題・エラーメッセージ
|
1
問題点の修正
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
saveボタンからの画面遷移
|
body
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
###前提・実現したいこと
|
2
|
-
DjangoGirlsというチュートリアルに従って、Pythonのdjangoを使いblogを作成しようとしています。そこで、ブログの投稿ページは作成できたものの、
|
2
|
+
DjangoGirlsというチュートリアルに従って、Pythonのdjangoを使いblogを作成しようとしています。そこで、ブログの投稿ページは作成し、データをデータベースに保存することはできたものの、次の画面に遷移することができずエラーが出てしまいました。
|
3
3
|
■ [参照ページ](https://djangogirlsjapan.gitbooks.io/workshop_tutorialjp/content/django_forms/)
|
4
4
|
|
5
5
|
###発生している問題・エラーメッセージ
|