質問編集履歴

1

コードを編集したのでそれに対するコードレビューをお願いしたいです。

2020/01/12 07:24

投稿

oinari03
oinari03

スコア59

test CHANGED
File without changes
test CHANGED
@@ -5,6 +5,8 @@
5
5
  ・ログインフォームからそのIDを入力し、一致したら次の画面に遷移
6
6
 
7
7
  ・IDが一致しなかったらエラーメッセージ表示
8
+
9
+ ・sqlはつかわないで、if文だけで作りたいです。
8
10
 
9
11
 
10
12
 
@@ -18,7 +20,7 @@
18
20
 
19
21
  ```python
20
22
 
21
- from flask import Flask, render_template
23
+ from flask import Flask, request,render_template
22
24
 
23
25
 
24
26
 
@@ -26,11 +28,13 @@
26
28
 
27
29
 
28
30
 
31
+
32
+
33
+ password = "aaa"
34
+
29
35
  @app.route('/')
30
36
 
31
37
  def main():
32
-
33
- password = "aaa"
34
38
 
35
39
  message = "Passwordを入力して下さい"
36
40
 
@@ -42,9 +46,17 @@
42
46
 
43
47
  def login():
44
48
 
49
+ password = request.form["password"]
50
+
45
51
  message = "Loginしました"
46
52
 
53
+ if password == "1234":
54
+
47
- return render_template("login.html",message = message)
55
+ return render_template("login.html",message = message)
56
+
57
+ else:
58
+
59
+ return render_template('main.html')
48
60
 
49
61
 
50
62
 
@@ -72,9 +84,9 @@
72
84
 
73
85
  <form action="/login" method="post">
74
86
 
75
- <label for="article">Password</label>
87
+ <label for="Password">Password</label>
76
88
 
77
- <input type="text" name = "article">
89
+ <input type="password" name = "pass">
78
90
 
79
91
  <button type="submit">送信する</button>
80
92
 
@@ -92,21 +104,15 @@
92
104
 
93
105
  {% block content %}
94
106
 
95
- {% if "article" == "aaa" %}
96
-
97
107
  <h1>書き込みました</h1>
98
108
 
99
- <p>{{ message}}</p>
109
+ <p>{{ message }}</p>
100
-
101
- {% elif "article" != "aaa" %}
102
110
 
103
111
  <form action="/" method="get">
104
112
 
105
113
  <button type="submit">戻る</button>
106
114
 
107
115
  </form>
108
-
109
- {% endif %}
110
116
 
111
117
  {% endblock %}
112
118
 
@@ -118,17 +124,9 @@
118
124
 
119
125
  ### 解決したいこと
120
126
 
121
- いまのままだと、どんなIDを入力しても/loginに画面が遷移してしまいます。これを予め用意したIDだけでしか画面遷移出来ないようにしたいです。
122
127
 
123
128
 
124
-
125
- 個人的はif文をFlaskで書くやりが出来れば良いのではいかともっています。
129
+ エラー文対する解決策と、他の考え方なます。
126
-
127
-
128
-
129
- 他の記事などを拝見しましたがどれもSQLを使うような記事ばかりでして、そんなに大量のIDを登録する使い方をするわけでもないので(単純に技術不足もありますが、、、)SQLは使わないやり方でやりたいです。
130
-
131
-
132
130
 
133
131
 
134
132