flask入门教程(20) - 部署到heroku

heroku

heroku在2010年被Salesforce.com收购。Heroku作为最开始的云平台之一,从2007年6月起开发,当时它仅支持Ruby,但后来增加了对Java、Node.js、Scala、Clojure、Python以及PHP和Perl的支持。它是免费的,所以我们这次部署就以它为例子。

开始

首先我们在heroku上注册一个账号,然后下载heroku的cli工具,从这里下载:heroku-cli

在这里插入图片描述
下载完工具后我们在命令行中输入heroku检测:

CLI to interact with Heroku

VERSION
  heroku/7.27.1 win32-x64 node-v11.14.0

USAGE
  $ heroku [COMMAND]

COMMANDS
  access          manage user access to apps
  addons          tools and services for developing, extending, and operating your app
  apps            manage apps on Heroku
  auth            check 2fa status
  authorizations  OAuth authorizations
  autocomplete    display autocomplete installation instructions
  buildpacks      scripts used to compile apps
  certs           a topic for the ssl plugin
  ci              run an application test suite on Heroku
  clients         OAuth clients on the platform
  config          environment variables of apps
  container       Use containers to build and deploy Heroku apps
  domains         custom domains for apps
  drains          forward logs to syslog or HTTPS
  features        add/remove app features
  git             manage local git repository for app
  help            display help for heroku
  keys            add/remove account ssh keys
  labs            add/remove experimental features
  local           run Heroku app locally
  logs            display recent log output
  maintenance     enable/disable access to app
  members         manage organization members
  notifications   display notifications
  orgs            manage organizations
  pg              manage postgresql databases
  pipelines       groups of apps that share the same codebase
  plugins         list installed plugins
  ps              Client tools for Heroku Exec
  psql            open a psql shell to the database
  redis           manage heroku redis instances
  regions         list available regions for deployment
  releases        display the releases for an app
  reviewapps      disposable apps built on GitHub pull requests
  run             run a one-off process inside a Heroku dyno
  sessions        OAuth sessions
  spaces          manage heroku private spaces
  status          status of the Heroku platform
  teams           manage teams
  update          update the Heroku CLI
  webhooks        setup HTTP notifications of app activity

这样就证明安装成功了。

新的应用

首先准备好一个简洁的flask应用:

- templates
  - index.html
- static
  - test.jpg
- requirements.txt
- Procfile
- Procfile.windows
- app.py

然后创建git仓库:

git init
git add *
git commit -m "<提交信息>"

然后登录:

heroku login

然后进入目录,创建应用:

heroku create <应用名字>

然后你的git远程仓库会多出来一个heroku为你创建的仓库。假如呈现出这样,说明名字被占用了,比如convert这个名字:

Creating ⬢ convert... !
 !    Name convert is already taken

然后我们需要创建heroku专属的Procfile:

web: gunicorn app:app

和Procfile.windows:

web: python app.py

注意在requirements.txt加上gunicorn:

flask
gunicorn

然后我们推送到heroku的远程仓库:

git push heroku master

推送过程会比较长,因为heroku要进行探测,下载依赖包和部署。推送完成后你就能在这个网址看到你的应用了:

http://<应用名称>.herokuapp.com

比如我的三个应用:

http://cishen.herokuapp.com
http://converted.herokuapp.com
http://gobili.herokuapp.com

还有很多东西,我们下次继续。

下次见!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值