質問編集履歴

6

ディレクトリ編集

2018/10/19 00:33

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
@@ -50,9 +50,9 @@
50
50
 
51
51
   -venv
52
52
 
53
-   flask.py
53
+  flask.py
54
54
 
55
-   hello.db
55
+  hello.db
56
56
 
57
57
  ```
58
58
 

5

タグついか

2018/10/19 00:33

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
File without changes

4

追加

2018/10/18 09:13

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
@@ -107,3 +107,9 @@
107
107
  return render_template('show.html', entries=entries)
108
108
 
109
109
  ```
110
+
111
+ 実行環境:
112
+
113
+ OS:Mac
114
+
115
+ IDE:Pycharm

3

色々コード追加

2018/10/18 09:12

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
@@ -32,25 +32,29 @@
32
32
 
33
33
  ディレクトリ構造
34
34
 
35
+ ```
36
+
35
37
  flask
36
38
 
37
- -media/
39
+  -media/
38
40
 
39
- 1.png
41
+   1.png
40
42
 
41
- -static/
43
+  -static/
42
44
 
43
- stylesheet.css
45
+   stylesheet.css
44
46
 
45
- -templates/
47
+  -templates/
46
48
 
47
- show.html
49
+   show.html
48
50
 
49
- -venv
51
+  -venv
50
52
 
51
- flask.py
53
+   flask.py
52
54
 
53
- hello.db
55
+   hello.db
56
+
57
+ ```
54
58
 
55
59
 
56
60
 
@@ -59,3 +63,47 @@
59
63
  書き方が違うかもしれませんが、
60
64
 
61
65
  ディレクトリ構造はこのような感じです。
66
+
67
+
68
+
69
+ 画像をアップロードするコード:
70
+
71
+ ```python
72
+
73
+ # 画像アップロード
74
+
75
+ @app.route('/image_entry', methods=['GET', 'POST'])
76
+
77
+ def image_entry():
78
+
79
+ if request.method == 'POST':
80
+
81
+ img_file = request.files['img_file']
82
+
83
+ if img_file and allowed_file(img_file.filename):
84
+
85
+ filename = secure_filename(img_file.filename)
86
+
87
+ img_file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
88
+
89
+ img_url = '/uploads/' + filename
90
+
91
+ return render_template('show.html', media=img_url)
92
+
93
+ ```
94
+
95
+ show.htmlを表示するコード:
96
+
97
+ ```python
98
+
99
+ @app.route('/')
100
+
101
+ def show():
102
+
103
+ cur = g.db.execute('select id, title, text from entries order by id asc')
104
+
105
+ entries = [dict(id = row[0] ,title=row[1], text=row[2]) for row in cur.fetchall()]
106
+
107
+ return render_template('show.html', entries=entries)
108
+
109
+ ```

2

編集

2018/10/18 09:08

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
@@ -34,23 +34,23 @@
34
34
 
35
35
  flask
36
36
 
37
- -media
37
+ -media/
38
38
 
39
- 1.png
39
+ 1.png
40
40
 
41
- -static
41
+ -static/
42
42
 
43
- stylesheet.css
43
+ stylesheet.css
44
44
 
45
- -templates
45
+ -templates/
46
46
 
47
- show.html
47
+ show.html
48
48
 
49
- -venv
49
+ -venv
50
50
 
51
- flask.py
51
+ flask.py
52
52
 
53
- hello.db
53
+ hello.db
54
54
 
55
55
 
56
56
 

1

ディレクトリ追加

2018/10/18 09:01

投稿

panda_fy
panda_fy

スコア13

test CHANGED
File without changes
test CHANGED
@@ -25,3 +25,37 @@
25
25
 
26
26
 
27
27
  よろしくお願いいたします。
28
+
29
+
30
+
31
+ 追加:
32
+
33
+ ディレクトリ構造
34
+
35
+ flask
36
+
37
+ -media
38
+
39
+ 1.png
40
+
41
+ -static
42
+
43
+ stylesheet.css
44
+
45
+ -templates
46
+
47
+ show.html
48
+
49
+ -venv
50
+
51
+ flask.py
52
+
53
+ hello.db
54
+
55
+
56
+
57
+ flask.pyとhello.dbはflask直下に置いてあります。
58
+
59
+ 書き方が違うかもしれませんが、
60
+
61
+ ディレクトリ構造はこのような感じです。