-
安装git,如果已经有git,可以忽略
sudo apt-get install git -
建立一个文件夹,比如叫flask_heroku,专门用来放flask的东西 到这个文件夹下
cd flask_heroku -
install pip on ubuntu if don't have it
sudo apt-get install python-pip -
install virtualenv in ubuntu
sudo apt-get install python-virtualenvon windows, you can dopip install virtualenv -
run to create temperorary enviroment called venv
sudo virtualenv venv这时候你的flask_heroku下面会多了一个文件夹venc,下面安装所有的东西都要使用venv/bin/pip,不能使用系统自带的pip -
activate the virtual enviroment
source venv/bin/activatedeactivate the virtual enviromentdeactivate下面用venv/bin/pip安装flask,flask-wtf和其他所有东西的时候,都要在virtual enviroment下面安装,否则requirements.txt会有问题 -
install flask(确认已经激活virtual enviroment)
venv/bin/pip install Flaskusevenv/bin/pip listorvenv/bin/pip show flaskto check if you have flask installed. -
install useful packages if you want(确认已经激活virtual enviroment)
venv/bin/pip install flask-wtf venv/bin/pip install flask-mail -
register on heroku.com to get username/password
-
download heroku toolbelt on ubuntu
wget -O- https://toolbelt.heroku.com/install-ubuntu.sh | sh -
log on to heroku from your command line
heroku login -
create heroku app from your command line or from the heroku.com from comman line
heroku create my-heroku-namefrom heroku.com do it directly in https://dashboard.heroku.com/apps 可以更改你的app的名字 https://dashboard.heroku.com/apps/pydata/settings -
配置postgres数据库
heroku create my-heroku-app-cn -
install prodcution web server gunicorn(确认已经激活virtual enviroment)
venv/bin/pip install gunicorn -
产生必要的两个文件requirements.txt和Procfile 产生requirements.txt
venv/bin/pip freeze > requirements.txt产生Procfile 用任意文本编辑器建立一个名字为Procfile的文件,在里面输入web: gunicorn app:app -
git部署 去掉不必要的文件,只留下必要的文件和文件夹
git git add . git commit -m "first flask app test" git push heroku master