Using cx_freeze in a flash application

I am using Flask to develop a python application. At the moment, I want this application to run locally. It works locally fine through python, but when I use cx_freeze to turn it into exe for Windows, I can no longer use the Flask.render_template () method. The moment I try to execute render_template, I get an http 500 error, just as if the html template that I am trying to execute does not exist.

The main python file is called index.py. First I tried to run: cxfreeze index.py . This did not include the "templates" directory from the Flask project in the "dist" cxfreeze directory. So I tried using this setup.py script and running python setup.py build . Now this includes the templates folder and the index.html template, but I still get the http: 500 error when it tries to display the template.

 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 = ' me@me.com ', options = {'build_exe': {'excludes':excludes,'include_files':includefiles}}, executables = [Executable('index.py')] ) 

Here is an example method from a script:

 @app.route('/index', methods=['GET']) def index(): print "rendering index" return render_template("index.html") 

If I run index.py , then in the console I get:

  * 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 - 

and the page displays correctly in my browser, but if I run index.exe , I get

  * 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 - 

and

 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. 

in my browser.

If I return raw html like

 @app.route('/index', methods=['GET']) def index(): print "rendering index" return "This works" 

then it works great. Thus, a possible job is to stop using Flask templates and hard code all the html logic into the main python file. It gets very dirty, so I would like to avoid it if possible.

I am using 32-bit Python 2.7, Cx_freeze for the 32-bit version of Python 2.7 and Flask 0.9

Thanks for any help and ideas!

+7
source share
1 answer

After many false traces breaking through Flask and Jinga modules, I finally found a problem.

CXFreeze does not recognize that jinja2.ext is dependent and does not include it.

I fixed this by including import jinja2.ext in one of the python files.

CXFreeze then added ext.pyc to library.zip \ jinja. (Copying it manually after assembly also works)

Just in case, if someone else goes crazy to try using Flask to develop local applications :)

+15
source

All Articles