私はFlaskを使ってPythonアプリケーションを開発しています。現時点では、このアプリをローカルで実行したいと考えています。これはPythonでローカルで正常に動作しますが、cx_freezeを使用してWindows用のexeファイルに変換すると、Flask.render_template()メソッドを使用できなくなります。私がrender_templateを実行しようとすると、私はレンダリングしようとしているHTMLテンプレートが存在しないかのように、http:// 500のエラーが発生します。フラスコアプリでcx_freezeを使用
メインのpythonファイルはindex.pyと呼ばれます。最初は実行しようとしました:cxfreeze index.py
。これには、cxfreeze "dist"ディレクトリのFlaskプロジェクトの "templates"ディレクトリは含まれていませんでした。そこで私はこのsetup.pyスクリプトを使って、python setup.py build
を実行しようとしました。テンプレートフォルダとindex.htmlテンプレートが含まれていますが、テンプレートをレンダリングしようとするとまだhttp:500エラーが表示されます。ここで
from cx_Freeze import setup,Executable
includefiles = [ 'templates\index.html']
includes = []
excludes = ['Tkinter']
setup(
name = 'index',
version = '0.1',
description = 'membership app',
author = 'Me',
author_email = '[email protected]',
options = {'build_exe': {'excludes':excludes,'include_files':includefiles}},
executables = [Executable('index.py')]
)
スクリプトからの例示的な方法である:私は私が得るコンソールで、その後index.py
を実行した場合
@app.route('/index', methods=['GET'])
def index():
print "rendering index"
return render_template("index.html")
:
* Running on http://0.0.0.0:5000/
rendering index
127.0.0.1 - - [26/Dec/2012 15:26:41] "GET/HTTP/1.1" 200 -
127.0.0.1 - - [26/Dec/2012 15:26:42] "GET /favicon.ico HTTP/1.1" 404 -
とページが私のブラウザで正しく表示されます私がを実行した場合、私は
* Running on http://0.0.0.0:5000/
rendering index
127.0.0.1 - - [26/Dec/2012 15:30:57] "GET/HTTP/1.1" 500 -
127.0.0.1 - - [26/Dec/2012 15:30:57] "GET /favicon.ico HTTP/1.1" 404 -
私のブラウザで
と
Internal Server Error
The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there is an error in the application.
。
生のHTMLを返します。
@app.route('/index', methods=['GET'])
def index():
print "rendering index"
return "This works"
だから、可能な回避策は、Flaskのテンプレートの使用を止め、すべてのhtmlロジックをメインのpythonファイルにハードコードすることです。これは非常に乱雑になるので、私は可能な場合は避けたいです。
私は、Python 2.7の32ビット、Cx_freezeのPython 2.7用の32ビット、およびフラスコに任意のヘルプやアイデアのための0.9
感謝を使用しています!