質問編集履歴

1

情報の修正

2017/12/12 10:51

投稿

退会済みユーザー
test CHANGED
File without changes
test CHANGED
@@ -1,94 +1,4 @@
1
- Page not found (404) エラーが出ます。views.pyに
1
+ Page not found (404) エラーが出ます。
2
-
3
- ```ここに言語を入力
4
-
5
- def regist(request):
6
-
7
- regist_form = RegisterForm(request.POST or None)
8
-
9
- profile_form = ProfileForm(request.POST or None)
10
-
11
- context = {
12
-
13
- 'regist_form': regist_form,
14
-
15
- 'profile_form': profile_form,
16
-
17
- }
18
-
19
- return render(request, 'registration/regist.html', context)
20
-
21
-
22
-
23
- @require_POST
24
-
25
- def regist_save(request):
26
-
27
-
28
-
29
- regist_form = RegisterForm(request.POST or None)
30
-
31
- profile_form = ProfileForm(request.POST or None)
32
-
33
-
34
-
35
- if request.method == "POST" and regist_form.is_valid() and profile_form.is_valid():
36
-
37
- regist = regist_form.save(commit=False)
38
-
39
- regist.is_staff = True
40
-
41
- regist.save()
42
-
43
-
44
-
45
- profile = profile_form.save(commit=False)
46
-
47
- profile.user = regist
48
-
49
- profile.save()
50
-
51
- return render(request, 'registration/detail.html')
52
-
53
-
54
-
55
- @login_required
56
-
57
- def detail(request):
58
-
59
- return render(request, 'registration/detail.html')
60
-
61
-
62
-
63
- def logout_view(request):
64
-
65
- logout(request)
66
-
67
- return redirect('/accounts/regist')
68
-
69
- ```
70
-
71
- とコードを書きました。
72
-
73
- urls.pyには
74
-
75
- ```ここに言語を入力
76
-
77
- urlpatterns = [
78
-
79
- url(r'^detail$', views.detail,name='detail'),
80
-
81
- url(r'^logout_view', views.logout_view,name='logout_view'),
82
-
83
- url(r'^regist/$', views.regist,name='regist'),
84
-
85
- url(r'^regist_save/$', views.regist_save, name='regist_save'),
86
-
87
- ]
88
-
89
- ```
90
-
91
- のように書きました。
92
2
 
93
3
  今、regist・regist_saveメソッドが呼ばれた後detail.htmlが表示されるのですが、その時のURLはhttp://localhost:8000/accounts/regist_save/ です。本来はhttp://localhost:8000/accounts/detail/ を呼び出したいのですが。その/accounts/regist_save/ の URLでdetail.htmlが表示されている時さらにlogout_viewメソッドを呼び出すと、
94
4