viraptor
viraptor

Reputation: 34205

How to properly package flask application with static files

I'm trying to create a python package for a webapp (flask based) and I'd like to get some files installed in a known directory.

For example flask tries to find the templates and static directories inside the current package when running the integrated server (paste-based). But in production I'd rather like those directories installed in a more specific place like virtualenv/share/package-name/{static,templates}. Otherwise they would be somewhere under lib/python-2.x/... which doesn't seem appropriate.

I tried to install the files using the data_files parameter in setup.py, but that doesn't seem to be useful for whole trees (error: can't copy 'xxx': doesn't exist or not a regular file).

What's the proper solution in this situation?

Upvotes: 10

Views: 4438

Answers (1)

Mark Lakewood
Mark Lakewood

Reputation: 2030

What you could do is package up your virtual env and static files into a native package (.deb or .rpm) and then you could place these anywhere you want. I wrote a blog post on this here. It uses a handy little ruby gem called fpm and although I dont seperate my static files from my python package you would be able to by adding another path mapping on the end of the fpm command like so

    fpm -s dir -t deb -n food-truck -v 0.1 -d "python,python-dev,postgresql" /home/ubuntu/food_truck-build/=/home/ubuntu/foodtruck.com <path to static files>=<destination of static files>

You could use fpm to specify other config files such as your nginx config etc as well. But thats up to you, and might mean your deployment is a little less flexible.

Hope that helps!

Upvotes: 3

Related Questions