These instructions assume that you have set up the heroku tools and have an account, also that you have python 2.7 and the virtualenv package installed. See the notes below to links on how to set these up.
- Create the directory where you want to develop the app itself. I use d:\heroku\<app_name>
- Create a virtual python environment with virtualenv
- Activate the virtual environment and install flask
venv\scripts\activate pip install flask
- Initialize a git repo in the new directory with:
- Create the app with the heroku toolbelt, you can specify a name for the app or just let heroku assign one, I usually just let heroku assign one at this stage, you can change it at a later date if you need to.
heroku apps:createThis will create a remote repo for git called heroku
- Create the minimal files required to run an app.
This is the file that tells the heroku app what to run, find out more here. In this case we just want a simple web dyno running our server. It needs just one line:
web: python server.py
This is the pip requirements file that heroku uses to install the correct python packages. It can be generated with the commandline:
pip freeze > requirements.txtFor a simple flask app the file looks like:
Flask==0.9 Jinja2==2.6 Werkzeug==0.8.3
This is the python script that runs the server on the heroku instance. For this example lets just have it return "hello world" from the index page. The file looks like:
import os from flask import Flask app = Flask(__name__) @app.route("/") def hello(): return "Hello World!" if __name__ == "__main__": port = int(os.environ.get('PORT', 5000)) app.run(host='0.0.0.0', port=port)
Now add the files to git
git add *
Now commit the files
git commit -m "Add the minimal required files
Now push the files to the heroku instance
git push heroku master
The app can now be opened by using the open command
heroku apps:openor run locally with
- See https://api.heroku.com/signup to create an account
- Install the toolbelt from https://toolbelt.herokuapp.com/
- Install virtualenv from http://pypi.python.org/pypi/virtualenv
The only problem is there are difficulties with Heroku Toolbelt on Windows. It installs the wrong version of Foreman, so you must do a 'gem uninstall' and then 'gem install' of version 0.61.
But to do that you'll have to remove the readonly status that Heroku toolbelt assigns to the ruby directory, and that involves changing system permissions (right click on the directory, then Properties-->Security).
Secondly, the gunicorn web server which is part of Toolbelt crashes using the default install. Haven't solved that one yet. Does anyone know of a workaround?
Interesting. I had never looked at the version of Foreman installed as it all "just works" for me.
I usually cheat anyway and just run the web app without foreman.
Just made my life easier man ! Thanks a lot !
Thxs man you effort saved lot's of time
Post a Comment