私は次の指示に従います。
run() メソッドは、ローカルの開発サーバーを起動するのに便利ですが、コードを変更するたびに手動で再起動する必要があります。それはあまり良いことではなく、Flask の方がうまくいく可能性があります。デバッグ サポートを有効にすると、コードの変更時にサーバーが自動的に再読み込みされ、問題が発生した場合に便利なデバッガーも提供されます。
私は設定しました:
app.run(debug=True)
しかし、デバッグ モードはまだ有効になっていないようです。その理由は何ですか?
これはコードです (1 つのファイルのみ):
import os
import glob
import pandas as pd
from flask import Flask
from regex_file_cleaner import clean_csv_file
app = Flask(__name__)
APP_ROOT = os.path.dirname(os.path.abspath(__file__))
APP_STATIC = os.path.join(APP_ROOT, 'static')
@app.route('/1/1')
def task1():
array = [['a', 'b', 'c'], ['d', 'e', 'f']]
result = ' '.join([' '.join(i) for i in array])
return ("<pre>' '.join([' '.join(i) for i in array])</pre>"
" applied to:<pre>%s</pre>results in: %s") % (str(array), result)
@app.route('/1/2')
def task2():
dataframes_collection = []
os.chdir(APP_STATIC+"/some/path")
for csv_file in glob.glob("*.csv"):
country_code = csv_file.split(' ')[1].split('.')[0]
start, end = clean_csv_file(csv_file)
df = pd.read_csv(csv_file, sep='\t', header=False, skiprows=start, parse_dates=True)[:end]
df['Country'] = country_code
dataframes_collection.append(df)
concatenated = pd.concat(dataframes_collection, ignore_index=True)
raport = "<h1>Raw data</h1> %s <h1>Summary of the day.</h1> %s" % (
concatenated.to_html(),
concatenated.groupby(
['Days'])['Page Impressions', 'Visits', 'Bounces'].sum().to_html(
justify='right'))
return raport
@app.route('/')
def hello_world():
return 'Hello World!'
if __name__ == '__main__':
app.debug = True
app.run()
これは私の出力ですpip freeze
:
Flask==0.10.1
Jinja2==2.7.3
MarkupSafe==0.23
Werkzeug==0.9.6
backports.ssl-match-hostname==3.4.0.2
certifi==14.05.14
itsdangerous==0.24
matplotlib==1.3.1
nose==1.3.3
numpy==1.8.1
pandas==0.14.1
pyparsing==2.0.2
python-dateutil==2.2
pytz==2014.4
scipy==0.14.0
six==1.7.3
tornado==4.0
wsgiref==0.1.2
コンソール出力:
(rocket)➜ demo python test.py
* Running on http://127.0.0.1:5000/
* Restarting with reloader
127.0.0.1 - - [02/Aug/2014 19:50:49] "GET /1/2 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:51] "GET /1/2 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:54] "GET /1 HTTP/1.1" 404 -
127.0.0.1 - - [02/Aug/2014 19:50:56] "GET /1/1 HTTP/1.1" 200 -
* Detected change in 'test.py', reloading
* Restarting with reloader
127.0.0.1 - - [02/Aug/2014 19:53:37] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:41] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:54] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:53:57] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:06] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:47] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:54:54] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:55:00] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:58:29] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:59:15] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 19:59:16] "GET /1/1 HTTP/1.1" 200 -
* Detected change in '/Users/andi/FLASK/demo/regex_file_cleaner.py', reloading
* Restarting with reloader
* Detected change in '/Users/andi/FLASK/demo/regex_file_cleaner.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
* Detected change in 'test.py', reloading
* Restarting with reloader
127.0.0.1 - - [02/Aug/2014 20:00:47] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:02:44] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:04:38] "GET /1/2 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:04:42] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:06] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:08] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:14] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:17] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:05:21] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:06:10] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:07:02] "GET /1/1 HTTP/1.1" 200 -
127.0.0.1 - - [02/Aug/2014 20:07:04] "GET /1/2 HTTP/1.1" 200 -
^C%
アップデート:
メインファイルの変更は認識されませんが、ファイルに加えられた変更はregex_file_cleaner.py
常に認識されることに気付きました。