質問編集履歴
4
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -52,10 +52,11 @@
|
|
52
52
|
return render/template('index.html')
|
53
53
|
|
54
54
|
@app.route('/result', methods=['GET', 'POST'])
|
55
|
+
def result():
|
55
|
-
|
56
|
+
name = request.form["name"]
|
56
|
-
|
57
|
+
num = request.form["num"]
|
57
|
-
|
58
|
+
ui = nn(name,num)
|
58
|
-
|
59
|
+
return render_template('index.html',ui=ui)
|
59
60
|
|
60
61
|
if __name__ == '__main__':
|
61
62
|
app.run(debug=True)
|
3
追加
title
CHANGED
@@ -1,1 +1,1 @@
|
|
1
|
-
|
1
|
+
ローカルで動いたファイルをサーバーで動かすと405エラーになる
|
body
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
### 前提・実現したいこと
|
2
2
|
|
3
|
-
|
3
|
+
ロリポップFTPでファイルをアップロードしましたが、ローカル環境では動いたファイルがエラーになります。
|
4
4
|
|
5
|
+
HTMLからPYthonへ受け渡す時に405エラーが表示されます。
|
6
|
+
|
5
7
|
こちらのサイトを参考にしました。
|
6
8
|
https://qiita.com/Rowing0914/items/de16bc2676705bd94d24
|
7
9
|
|
8
10
|
### 発生している問題・エラーメッセージ
|
9
|
-
|
10
|
-
ターミナルでpython index.py後、http://localhost:5000/の結果です
|
11
11
|
```
|
12
12
|
Method Not Allowed
|
13
13
|
The method is not allowed for the requested URL.
|
@@ -16,98 +16,6 @@
|
|
16
16
|
調べた結果、405エラーはURLやファイルの配置がおかしいという指摘が多数あったので確認しましたが、解決方法がわからなかったので、質問させていただきました。
|
17
17
|
|
18
18
|
### 該当のソースコード
|
19
|
-
|
20
|
-
```Procfile
|
21
|
-
web: gunicorn -b 0.0.0.0:$PORT app:app
|
22
|
-
```
|
23
|
-
```README
|
24
|
-
# Introduction
|
25
|
-
This is a demo project for playing with Heroku!
|
26
|
-
For simplicity, I am using quite simple Flask app, so if you would like to modify the code, it's totally fine! I mean, I would like to encourage to it.
|
27
|
-
But before, that I would recommend you to try following this project firstly!
|
28
|
-
Tnen convert it into your style later!
|
29
|
-
|
30
|
-
## Prerequiresites
|
31
|
-
Since I would like you to enjoy your life with Heroku and showing your achievement ASAP, I have skipped the explanaiton on the code, especially flask part.
|
32
|
-
So if it's needed, please familiarise yourself with Flask.
|
33
|
-
|
34
|
-
Flask Official Doc
|
35
|
-
http://flask.pocoo.org/docs/1.0/quickstart/
|
36
|
-
|
37
|
-
|
38
|
-
## Python Version
|
39
|
-
3.6.* or 2.7.*
|
40
|
-
|
41
|
-
## Agenda
|
42
|
-
1. What is Heroku?
|
43
|
-
2. Registration(Sign up)
|
44
|
-
3. Installation of CLI tool
|
45
|
-
4. Deployment
|
46
|
-
|
47
|
-
## 1. What is Heroku?
|
48
|
-
Heroku is a cloud platform that lets companies build, deliver, monitor and scale apps — we're the fastest way to go from idea to URL, bypassing all those infrastructure headaches.
|
49
|
-
|
50
|
-
## 2. Registration(Sign up)
|
51
|
-
Check this link and fill the blank.
|
52
|
-
https://signup.heroku.com/
|
53
|
-
|
54
|
-
## 3. Installation of CLI tool
|
55
|
-
Using the cli tool, we have an access to Heroku service from our terminal/CMD.
|
56
|
-
Link: https://devcenter.heroku.com/articles/heroku-cli
|
57
|
-
So pick one according to your machine.
|
58
|
-
|
59
|
-
## 4. Deployment
|
60
|
-
In this section, I will put some comment on between the line of the bash command,
|
61
|
-
so check them a bit carefully!
|
62
|
-
|
63
|
-
``bash
|
64
|
-
# first you need to login!
|
65
|
-
$ heroku login
|
66
|
-
# <outcome>
|
67
|
-
# Email: ??
|
68
|
-
# Password: ??
|
69
|
-
# Logged in as : your-user-name
|
70
|
-
|
71
|
-
# get this repo
|
72
|
-
$ git clone https://github.com/Rowing0914/Heroku_training_flask.git
|
73
|
-
# move to the directory
|
74
|
-
$ cd Heroku_training_flask
|
75
|
-
# test on the local machine!
|
76
|
-
$ python app.py
|
77
|
-
# Be sure that this works properly!
|
78
|
-
``
|
79
|
-
|
80
|
-
By now you should see the images below by hitting your localhost:5000
|
81
|
-

|
82
|
-
|
83
|
-
then, let's move on to deploy it!
|
84
|
-
|
85
|
-
``bash
|
86
|
-
# this will assign the domain_name to your app
|
87
|
-
$ heroku create
|
88
|
-
``
|
89
|
-

|
90
|
-
|
91
|
-
``bash
|
92
|
-
# deploy!!
|
93
|
-
$ git push heroku master
|
94
|
-
``
|
95
|
-
|
96
|
-

|
97
|
-
|
98
|
-
bash
|
99
|
-
$ heroku open
|
100
|
-
|
101
|
-
DONE!
|
102
|
-
|
103
|
-

|
104
|
-
|
105
|
-
Thank you!
|
106
|
-
```
|
107
|
-
```requirements
|
108
|
-
Flask
|
109
|
-
gunicon
|
110
|
-
```
|
111
19
|
```layouthtml
|
112
20
|
<!DOCTYPE html>
|
113
21
|
<html>
|
@@ -116,7 +24,7 @@
|
|
116
24
|
<meta charset = "UTF-8">
|
117
25
|
</head>
|
118
26
|
<body>
|
119
|
-
<form method = "POST" action="
|
27
|
+
<form method = "POST" action="/result">
|
120
28
|
<label>名前<input type="text" value="" size="30" name="name"></label>
|
121
29
|
<label>番号<input type="text" value="" size="30" name="num"></label>
|
122
30
|
</form>
|
@@ -126,27 +34,31 @@
|
|
126
34
|
</html>
|
127
35
|
```
|
128
36
|
```indexhtml
|
129
|
-
{% extends "layout.html" %}
|
37
|
+
{% extends "layout.html" %}
|
38
|
+
{% block body %}
|
130
39
|
Welcome to Heroku!
|
131
40
|
This is your first app, isn't it?
|
132
41
|
Let's share your achievement with your friends!!
|
133
42
|
{% endblock %}
|
134
43
|
```
|
135
44
|
```indexpy
|
136
|
-
from flask import Flask , render_template
|
45
|
+
from flask import Flask , render_template , request
|
137
46
|
from models.fin import nn
|
138
47
|
|
139
48
|
app = Flask(__name__)
|
140
49
|
|
141
|
-
@app.route('/'
|
50
|
+
@app.route('/')
|
142
51
|
def index():
|
52
|
+
return render/template('index.html')
|
53
|
+
|
54
|
+
@app.route('/result', methods=['GET', 'POST'])
|
143
|
-
name = request.form
|
55
|
+
name = request.form["name"]
|
144
|
-
num = request.form
|
56
|
+
num = request.form["num"]
|
145
57
|
ui = nn(name,num)
|
146
58
|
return render_template('index.html',ui=ui)
|
147
59
|
|
148
60
|
if __name__ == '__main__':
|
149
|
-
app.run(
|
61
|
+
app.run(debug=True)
|
150
62
|
```
|
151
63
|
```finpy
|
152
64
|
def nn(name,num):
|
@@ -157,15 +69,12 @@
|
|
157
69
|
|
158
70
|
### **ディレクトリとファイル**
|
159
71
|
```
|
160
|
-
heroku_dir---
|
72
|
+
heroku_dir---index.py
|
161
|
-
README.md
|
162
|
-
requirements.txt
|
163
|
-
index.py(自作)
|
164
73
|
templates---index.html
|
165
74
|
layout.html
|
166
|
-
models---fin.py
|
75
|
+
models---fin.py
|
167
76
|
```
|
168
77
|
|
169
78
|
### 補足情報(FW/ツールのバージョンなど)
|
170
79
|
|
171
|
-
Mac、python3.8.8
|
80
|
+
Mac、python3.8.8,ロリポップFTPを使用しています
|
2
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -121,8 +121,6 @@
|
|
121
121
|
<label>番号<input type="text" value="" size="30" name="num"></label>
|
122
122
|
</form>
|
123
123
|
<h3>{{ui}}</h3>
|
124
|
-
</body>
|
125
|
-
</html>
|
126
124
|
{% block body %}{% endblock %}
|
127
125
|
</body>
|
128
126
|
</html>
|
1
追加
title
CHANGED
File without changes
|
body
CHANGED
@@ -170,4 +170,4 @@
|
|
170
170
|
|
171
171
|
### 補足情報(FW/ツールのバージョンなど)
|
172
172
|
|
173
|
-
Mac、python3.8、Herokuを使用しています
|
173
|
+
Mac、python3.8.8、Herokuを使用しています
|