Computer >> Máy Tính >  >> Lập trình >> Python

Làm thế nào để triển khai mô-đun python trên Heroku?


Giả sử bạn đã thiết lập Python 3.6, Pipenv và heroku CLI được cài đặt cục bộ và đăng nhập vào Heroku từ CLI bằng các bước được đề cập tại đây:https://devcenter.heroku.com/ article / get-start-with-python # set-up.

Ứng dụng của bạn cần có kho lưu trữ git để được triển khai tới heroku. Bạn cần cd trong thư mục chứa mã gốc git repo của bạn. Bây giờ bạn cần tạo một ứng dụng heroku bằng:

$ heroku create
Creating lit-bastion-5032 in organization heroku... done, stack is cedar-14

https://lit-bastion-5032.herokuapp.com/ | https://git.heroku.com/lit-bastion-5032.git

Git remote heroku đã được thêm vào

Khi bạn tạo một ứng dụng, một điều khiển từ xa git (được gọi là heroku) cũng được tạo và liên kết với kho lưu trữ git cục bộ của bạn. Heroku tạo một tên ngẫu nhiên (trong trường hợp này là lit-bastion-5032) cho ứng dụng của bạn hoặc bạn có thể chuyển một tham số để chỉ định tên ứng dụng của riêng bạn.

Bây giờ một điều khiển từ xa đã được thêm vào, bạn có thể đẩy mã của mình sang heroku bằng cách sử dụng:

$ git push heroku master
Counting objects: 232, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (217/217), done.
Writing objects: 100% (232/232), 29.64 KiB | 0 bytes/s, done.
Total 232 (delta 118), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote:
remote: -----> Python app detected
remote: -----> Installing python-3.6.0
remote: -----> Installing requirements with latest pipenv...
remote:        Installing dependencies from Pipfile.lock...
remote:      $ python manage.py collectstatic --noinput
remote:        58 static files copied to '/app/gettingstarted/staticfiles', 58 post-processed.
remote:
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote:
remote: -----> Compressing...
remote:        Done: 39.3M
remote: -----> Launching...
remote:        Released v4
remote:        https://lit-bastion-5032.herokuapp.com/ deployed to Heroku
remote:
remote: Verifying deploy... done.
To git@heroku.com:lit-bastion-5032.git
 * [new branch]      master -> master
Note that you need to specify your requirements(third party modules you are importing) with their version numbers(or without if you need latest one) in the requirements.txt. For example,
Flask==0.8
Jinja2==2.6
Werkzeug==0.8.3
certifi==0.0.8
chardet==1.0.1

Bạn có thể đọc thêm về điều này trên tài liệu về trăn heroku:https://devcenter.heroku.com/articles/python-pip