从本地计算机将静态资产部署到heroku - 无法打开文件'manage.py':[Errno 2]没有这样的文件或目录

时间:2016-03-28 22:07:39

标签: python django git heroku deployment

我正在尝试将我的资产文件部署到heroku,并在命令行界面中获得此输出:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python manage.py collectstatic
Running python manage.py collectstatic on neurorehabilitation.... up, run.5168
python: can't open file 'manage.py': [Errno 2] No such file or directory
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

对我来说很奇怪,因为我目前位于manage.py文件所在的目录/文件夹中

为了获得应用程序的早期部署,我选择以这种方式禁用环境变量DISABLE_COLLECT_STATIC

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set DISABLE_COLLECTSTATIC=1
Setting config vars and restarting neurorehabilitation... done
DISABLE_COLLECTSTATIC: 1
(nrb_dev) ➜  neurorehabilitation_projects git:(master)

根据以上所述,当我执行git push heroku master时,我可以部署mi应用程序:

remote: 
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 46M
remote: -----> Launching...
remote:        Released v15
remote:        https://neurorehabilitation.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy... done.
To https://git.heroku.com/neurorehabilitation.git
 * [new branch]      master -> master
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

根据之前的操作,在我的主链接https://neurorehabilitation.herokuapp.com/中有一个错误,我想这是因为静态文件没有被发送并被禁用。

这是对的吗?我不知道......

但是,有些奇怪的是,在我的Django Admin https://neurorehabilitation.herokuapp.com/admin/中,我可以在管理员中详细说明模板和css样式和js,然后,我知道heroku是否使用静态文件。< / p>

我的静态文件在这种情况下发生了什么?

但是,我遵循我的流程,在这个机会中,我可以远程部署到与manage.py命令相关的heroku操作。

我已经检查了这个,因为我可以执行我的应用程序迁移:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python  manage.py migrate        
Running python manage.py migrate on neurorehabilitation.... up, run.7836
Operations to perform:
  Apply all migrations: contenttypes, auth, userprofiles, sessions, medical_encounter_information, admin
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying userprofiles.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying userprofiles.0002_auto_20160225_2130... OK
  Applying userprofiles.0003_auto_20160225_2130... OK
  Applying medical_encounter_information.0001_initial... OK
  Applying medical_encounter_information.0002_auto_20160225_2130... OK
  Applying medical_encounter_information.0003_auto_20160225_2130... OK
  Applying medical_encounter_information.0004_auto_20160225_2211... OK
  Applying medical_encounter_information.0005_auto_20160225_2211... OK
  Applying medical_encounter_information.0006_auto_20160225_2303... OK
  Applying medical_encounter_information.0007_auto_20160229_2204... OK
  Applying medical_encounter_information.0008_auto_20160229_2208... OK
  Applying medical_encounter_information.0009_auto_20160301_0130... OK
  Applying medical_encounter_information.0010_auto_20160301_0312... OK
  Applying medical_encounter_information.0011_auto_20160301_1525... OK
  Applying medical_encounter_information.0012_auto_20160301_1601... OK
  Applying medical_encounter_information.0013_auto_20160301_1606... OK
  Applying medical_encounter_information.0014_auto_20160301_1629... OK
  Applying medical_encounter_information.0015_auto_20160301_1633... OK
  Applying medical_encounter_information.0016_auto_20160301_1636... OK
  Applying sessions.0001_initial... OK
  Applying userprofiles.0004_auto_20160225_2211... OK
  Applying userprofiles.0005_auto_20160225_2211... OK
  Applying userprofiles.0006_auto_20160225_2303... OK
  Applying userprofiles.0007_auto_20160229_2204... OK
  Applying userprofiles.0008_auto_20160229_2208... OK
  Applying userprofiles.0009_auto_20160301_0130... OK
  Applying userprofiles.0010_auto_20160301_0312... OK
  Applying userprofiles.0011_auto_20160301_1525... OK
  Applying userprofiles.0012_auto_20160301_1601... OK
  Applying userprofiles.0013_auto_20160301_1606... OK
  Applying userprofiles.0014_auto_20160301_1629... OK
  Applying userprofiles.0015_auto_20160301_1633... OK
  Applying userprofiles.0016_auto_20160301_1636... OK
(nrb_dev) ➜  neurorehabilitation_projects git:(master)

此外,我可以在我已部署的应用程序中创建一个来自我本地工具箱的超级用户...

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python  manage.py createsuperuser
Running python manage.py createsuperuser on neurorehabilitation.... up, run.5381

Username: bgarcial
Email address: bgarcial@sample.com
Password: 
Password (again): 
Superuser created successfully.
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

之后,我已禁用之前的环境变量设置DISABLE_COLLECTSTATIC=1我从设置信息中心heroku应用程序中删除了环境变量

但是,我再次执行heroku run python manage.py collectstatic命令,我收到此通知:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python  manage.py collectstatic
Running python manage.py collectstatic on neurorehabilitation.... up, run.9342

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    collected = self.collect()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    directories, files = storage.listdir(location)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
    for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

检查这个不方便,我猜我的错误就在这里:

directories, files = storage.listdir(location)
      File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
        for entry in os.listdir(path):
    FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'

而且,这告诉我在我的heroku应用程序中部署的static目录不存在

我已执行heroku run bash检查我的heroku应用程序中的结构目录,我可以在heroku中详细说明名为/app的根项目

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run bash    
    Running bash on neurorehabilitation.... up, run.5840
    ~ $ pwd 
    /app
    ~ $ 

我列出了/app内容,我在我的开发本地环境django项目中看到了类似方式的所有目录和文件

~ $ ls
avatars  custom_storages.py  django-multiselectfield-0.1.3.tar.gz  functional_tests  manage.py  medical_encounter_information  neurorehabilitation  Procfile  requirements  requirements.txt  runtime.txt  userprofiles

我的错误与此主题有关:

FileNotFoundError:[Errno 2]没有这样的文件或目录:'/ app / neurorehabilitation / settings / static'

然后我进入这些目录/app/neurorehabilitation/settings/,但我可以看到里面没有名为static的目录,就像heroku尝试搜索一样:

~ $ cd /app/neurorehabilitation/settings/
~/neurorehabilitation/settings $ ls
base.py  development.py  __init__.py  production.py  staging.py  testing.py
~/neurorehabilitation/settings $

这是因为根据我在本地开发环境中创建django项目时设置的结构目录。 我定义了以下内容:

enter image description here

然后,根据以前的情况......

为什么我执行部署到heroku时git,当没有从原始sproject源设置时,该进程正在搜索neurorehabilitation/settings/static的路径,这意味着,我的机器中的项目在部署到heroku之前? / p>

我可以采取什么行动? Heroku平台,当我执行heroku run python manage.py collectstatic命令时,尝试搜索一个目录taht不存在或不在我的项目的结构目录中设置?

即使我尝试通过/app/neurorehabilitation/settings/static创建heroku run bash文件夹,但这不起作用

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run bash
Running bash on test-nrb.... up, run.1604
~ $ cd neurorehabilitation/settings/
~/neurorehabilitation/settings $ mkdir static
~/neurorehabilitation/settings $ ls -all
total 36
drwx------ 3 u51683 dyno 4096 Apr  1 15:07 .
drwx------ 5 u51683 dyno 4096 Apr  1 15:02 ..
-rw------- 1 u51683 dyno 8106 Apr  1 15:02 base.py
-rw------- 1 u51683 dyno  684 Apr  1 15:02 development.py
-rw------- 1 u51683 dyno    0 Apr  1 15:02 __init__.py
-rw------- 1 u51683 dyno  930 Apr  1 15:02 production.py
-rw------- 1 u51683 dyno  530 Apr  1 15:02 staging.py
drwx------ 2 u51683 dyno 4096 Apr  1 15:07 static
-rw------- 1 u51683 dyno  488 Apr  1 15:02 testing.py
~/neurorehabilitation/settings $ exit
exit
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python manage.py collectstatic
Running python manage.py collectstatic on test-nrb.... up, run.5358

You have requested to collect static files at the destination
location as specified in your settings.

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    collected = self.collect()
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "/app/.heroku/python/lib/python3.4/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    directories, files = storage.listdir(location)
  File "/app/.heroku/python/lib/python3.4/site-packages/django/core/files/storage.py", line 299, in listdir
    for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'
(nrb_dev) ➜  neurorehabilitation_projects git:(master)

我不知道如何解决这个问题,为什么我的heroku部署不会创建类似于我的本地项目的结构目录?

有人是什么原因?

有可能在目前我还没有充分了解如何在结构目录和文件中通过git push heroku master上传到平台时如何在部署时立即使用heroku?

任何支持都将受到高度赞赏。

感谢您的指导:)

2 个答案:

答案 0 :(得分:1)

你有没有正确定义:

STATICFILES_DIRS

settings.py内?

您是否已在本地创建并将其添加到git(作为空目录...)。您拥有的跟踪表明此文件夹丢失。我创建了一个包含以下设置的简单项目:

~/Software/h/hrku $ tail hrku/settings.py 
USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

STATIC_URL = '/static/'

STATIC_ROOT = '/var/www/dj'
STATICFILES_DIRS = (os.path.join(os.path.dirname(__file__), '..', 'static'),)

正如您所看到的,STATICFILES_DIRS只包含一个不存在的目录:

~/Software/h/hrku $ ls -l /home/ozn/Software/h/hrku/static
ls: cannot access /home/ozn/Software/h/hrku/static: No such file or directory

命令collectstatic失败:

~/Software/h/hrku $ python manage.py collectstatic

You have requested to collect static files at the destination
location as specified in your settings:

    /var/www/dj

This will overwrite existing files!
Are you sure you want to do this?

Type 'yes' to continue, or 'no' to cancel: yes
Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/__init__.py", line 353, in execute_from_command_line
    utility.execute()
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/__init__.py", line 345, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/base.py", line 348, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/management/base.py", line 399, in execute
    output = self.handle(*args, **options)
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 176, in handle
    collected = self.collect()
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 98, in collect
    for path, storage in finder.list(self.ignore_patterns):
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/finders.py", line 112, in list
    for path in utils.get_files(storage, ignore_patterns):
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/contrib/staticfiles/utils.py", line 28, in get_files
    directories, files = storage.listdir(location)
  File "/home/ozn/.virtualenvs/h/lib/python3.5/site-packages/django/core/files/storage.py", line 299, in listdir
    for entry in os.listdir(path):
FileNotFoundError: [Errno 2] No such file or directory: '/home/ozn/Software/h/hrku/static'

我希望这能引导你解决问题。

答案 1 :(得分:0)

我将在这个答案中逐步展示我在Heroku中部署我的Django应用程序所做的工作。我希望这个问题对其他人有用,也要感谢那些花时间帮助我的人

<强> 1。在heroku中为我的静态文件设置我的设置

  • Heroku的设置配置

关键是能够将我的静态文件部署到Heroku是在我的settings/base.py中,同时也是ahmedOz123在他们的回复中所说的。

特别是,我有一个问题是PROJECT_ROOT指令的价值。 Heroku suggest PROJECT_ROOT这样的指令:

PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))

我做了设置PROJECT_ROOT我在BASE_DIR 中我已经settings/base.py},正如Heroku建议的那样,但总是出现错误,然后我接受了保留Django的BASE_DIR指令的选项与我上面引用的heroku配置相关的PROJECT_ROOT指令一样。

我遇到错误:

FileNotFoundError: [Errno 2] No such file or directory: '/app/neurorehabilitation/settings/static'

当我将BASE_DIR作为:

BASE_DIR = os.path.dirname(os.path.abspath(__file__))

最后,我的settings/base.py文件,内容为:

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/1.9/howto/static-files/

# This line tells Django to look for static files in a folder named static inside each of our apps.
STATIC_URL = '/static/'

当我BASE_DIRPROJECT_ROOT in heroku)我定义了文件系统路径时,最后我的STATICFILES_DIRS指令也受到了损害,就像Oz123在回复中引用了我一样。 :d

# With this configuration, Django will look for static files in a folder named static inside each app and into the neurorehabilitation/static folder
STATICFILES_DIRS = (
    os.path.join(BASE_DIR, "static"),
)

然后根据我项目中的部署设置(pink square in this image),我的设置/ production.py包含:

# ------ *** -------------
# For deploy to heroku
# ------ *** -------------

# Update database configuration with $DATABASE_URL.
db_from_env = dj_database_url.config(conn_max_age=500)
DATABASES['default'].update(db_from_env)

# Honor the 'X-Forwarded-Proto' header for request.is_secure()
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')

ALLOWED_HOSTS = ['*']

还需要在我的虚拟环境中安装dj-database-url包:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ pip install dj-database-url
Collecting dj-database-url
Installing collected packages: dj-database-url
Successfully installed dj-database-url-0.4.0
You are using pip version 8.1.0, however version 8.1.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

以这种方式在dj-database-url文件中添加requirements/production.txt包/依赖:

dj-database-url==0.4.0

这是我的不方便,当heroku部署应用程序并尝试将我的资产复制并处理到amazon S3时,collectstatic命令不起作用,我根据设置配置获取静态文件

此外,我想分享我的heroku部署过程,我认为这将是有用的甚至是轶事

要将Django应用程序部署到heroku,必须在项目根目录中包含以下文件:

  • requirements.txt file

I had the myproject/requirements/ folder in the root of my Django project, but the heroku deployment process does not works of this way

然后我在requirements /文件夹的相同级别或层次上创建一个具有以下内容的requirements.txt文件:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ cat requirements.txt 
-r requirements/production.txt%                                                 (nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

我的requirements/production.txt文件一直停留在:

-r base.txt
gunicorn==19.4.5
dj-database-url==0.4.0

requirements / base.txt文件包含我项目中所需的所有依赖项或包。

我需要Heroku在部署过程中安装3.4 python version,然后必须以这种方式在runtime.txt文件(在我的项目根目录中创建)中指明它

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ cat runtime.txt 
python-3.4.3
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗
  

Procfile是应用程序根目录中的文本文件   定义流程类型并显式声明应该使用什么命令   被执行以启动你的应用程序。

我的Procfile一直停留在:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ cat Procfile 
web: gunicorn neurorehabilitation.wsgi --log-file -
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

<强> 2。通过heroku toolbet测试我的机器的访问权限

必须安装Heroku toolbet

  

提供对Heroku命令行界面的访问权限   用于管理和扩展应用程序和插件等。

我以这种方式测试从我的机​​器访问heroku:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku login
Enter your Heroku credentials.
Email: botibagl@gmail.com
Password (typing will be hidden): 
Logged in as botibagl@gmail.com
(nrb_dev) ➜

第3。创建我的heroku应用程序

Accord to this response,因为要部署的应用程序是python/Django,所以heroku应用程序应该以这种方式创建:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku create test-nrb --buildpack heroku/python
Creating test-nrb... done, stack is cedar-14
Setting buildpack to heroku/python... done
https://test-nrb.herokuapp.com | https://git.heroku.com/test-nrb.git
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

然后,通过这种方式,我的heroku应用程序在我的网络仪表板中创建

enter image description here

<强> 4。在Heroku的项目中设置环境变量

我的本​​地项目中有一些环境变量用于隐藏我的密钥,数据库用户,名称和密码,一些访问我的亚马逊网络服务和s3帐户以及用于生产服务器的设置(DJANGO_SETTINGS_MODULE

必须向Heroku表明他将了解这些环境变量的方式。

Accord to this link我们将为已部署的应用程序配置变量。然后我在heroku中设置了我的环境变量:

  • DJANGO_SETTINGS_MODULE

我的部署将引导settings / production.py文件,该文件继承自settings / base.py,其中包含所有应用程序域包/依赖项。然后heroku中的DJANGO_SETTINGS_MODULE变量保持不变:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set DJANGO_SETTINGS_MODULE=neurorehabilitation.settings.production 
Setting config vars and restarting test-nrb... done
DJANGO_SETTINGS_MODULE: neurorehabilitation.settings.production
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 
  • SECRET_KEY

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set SECRET_KEY='mysecretkey'
Setting config vars and restarting test-nrb... done
SECRET_KEY: mysecretkey
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 
  • DATABASE_NAME

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set DATABASE_NAME=mydatabasename
Setting config vars and restarting test-nrb... done
DATABASE_NAME: mydatabasename
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 
  • DATABASE_USER

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set DATABASE_USER=mydatabaseuser
Setting config vars and restarting test-nrb... done
DATABASE_USER: mydatabaseuser
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 
  • DATABASE_PASSWORD :单引号中的值

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set DATABASE_PASSWORD='mydatabasepassword'
Setting config vars and restarting test-nrb... done
DATABASE_PASSWORD: mydatabasepassword
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗
  • 亚马逊网络服务访问密钥ID :单引号中的值

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set AWS_ACCESS_KEY_ID='my_aws_access_key_id'
Setting config vars and restarting test-nrb... done
AWS_ACCESS_KEY_ID: my_aws_access_key_id
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗
  • 亚马逊网络服务秘密访问密钥:单引号中的值

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set AWS_SECRET_ACCESS_KEY='my_aws_secret_access_key'
Setting config vars and restarting test-nrb... done
AWS_SECRET_ACCESS_KEY: my_aws_secret_access_key
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 
  • Amazon Web Services存储分区名称:单引号中的值

我执行:

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku config:set AWS_STORAGE_BUCKET_NAME='my-bucket-name-in-s3' 
Setting config vars and restarting test-nrb... done
AWS_STORAGE_BUCKET_NAME: my-bucket-name-in-s3
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

然后根据我的网络仪表板中的上述选项,环境变量包含:

enter image description here

<强> 5。对heroku存储库执行commit操作

首先我们检查要提交的文件

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git status
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   requirements.txt
    new file:   runtime.txt

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   neurorehabilitation/settings/base.py
    modified:   neurorehabilitation/settings/development.py
    modified:   neurorehabilitation/settings/production.py
    modified:   requirements.txt
    modified:   runtime.txt

Untracked files:
  (use "git add <file>..." to include in what will be committed)

    .idea/
    Procfile
    gunicorn_start

(nrb_dev) ➜  neurorehabilitation_projects git:(master)

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add requirements.txt 
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add runtime.txt     
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add Procfile 
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add neurorehabilitation/settings/base.py 
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add neurorehabilitation/settings/development.py
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git add neurorehabilitation/settings/production.py

进行commit操作

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git commit -m 'Setup changes and configurations for deploy to heroku'
[master 69d69fe] Setup changes and configurations for deploy to heroku
 6 files changed, 38 insertions(+), 5 deletions(-)
 create mode 100644 Procfile
 create mode 100644 requirements.txt
 create mode 100644 runtime.txt
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

<强> 6。将我们的代码应用程序部署到heroku存储库

之前,我检查了我的遥控器回购。我参考了heroku别名

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git remote -v
heroku  https://git.heroku.com/neurorehabilitation.git (fetch)
heroku  https://git.heroku.com/neurorehabilitation.git (push)
origin  https://bgarcial@bitbucket.org/bgarcial/neurorehabilitation_projects.git (fetch)
origin  https://bgarcial@bitbucket.org/bgarcial/neurorehabilitation_projects.git (push)
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗

部署到heroku存储库

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ git push heroku master 
Counting objects: 20, done.
Delta compression using up to 8 threads.
Compressing objects: 100% (13/13), done.
Writing objects: 100% (13/13), 1.17 KiB | 0 bytes/s, done.
Total 13 (delta 11), reused 0 (delta 0)
remote: Compressing source files... done.
remote: Building source:
remote: 
remote: -----> Using set buildpack heroku/python
remote: -----> Python app detected
remote:      $ pip install -r requirements.txt
remote: 
remote:      $ python manage.py collectstatic --noinput
remote:        Found another file with the destination path 'admin/css/forms.css'. It will be ignored since only the first encountered file is collected. If this is not what you want, make sure every static file has a unique path.
remote:        147 static files copied.
remote: 
remote: 
remote: -----> Discovering process types
remote:        Procfile declares types -> web
remote: 
remote: -----> Compressing...
remote:        Done: 46.1M
remote: -----> Launching...
remote:        Released v15
remote:        https://test-nrb.herokuapp.com/ deployed to Heroku
remote: 
remote: Verifying deploy.... done.
To https://git.heroku.com/test-nrb.git
   9f0d32f..fcc62c9  master -> master
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

<强> 7。执行迁移过程

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python manage.py migrate
Running python manage.py migrate on test-nrb.... up, run.1678
System check identified some issues:

WARNINGS:
medical_encounter_information.RehabilitationSession.date_session_begin: (fields.W161) Fixed default value provided.
        HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
medical_encounter_information.RehabilitationSession.date_session_end: (fields.W161) Fixed default value provided.
        HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
userprofiles.User.birth_date: (fields.W161) Fixed default value provided.
        HINT: It seems you set a fixed date / time / datetime value as default for this field. This may not be what you want. If you want to have the current date as default, use `django.utils.timezone.now`
Operations to perform:
  Apply all migrations: medical_encounter_information, userprofiles, contenttypes, auth, admin, sessions
Running migrations:
  Rendering model states... DONE
  Applying contenttypes.0001_initial... OK
  Applying contenttypes.0002_remove_content_type_name... OK
  Applying auth.0001_initial... OK
  Applying auth.0002_alter_permission_name_max_length... OK
  Applying auth.0003_alter_user_email_max_length... OK
  Applying auth.0004_alter_user_username_opts... OK
  Applying auth.0005_alter_user_last_login_null... OK
  Applying auth.0006_require_contenttypes_0002... OK
  Applying auth.0007_alter_validators_add_error_messages... OK
  Applying userprofiles.0001_initial... OK
  Applying admin.0001_initial... OK
  Applying admin.0002_logentry_remove_auto_add... OK
  Applying userprofiles.0002_auto_20160225_2130... OK
  Applying userprofiles.0003_auto_20160225_2130... OK
  Applying medical_encounter_information.0001_initial... OK
  Applying medical_encounter_information.0002_auto_20160225_2130... OK
  Applying medical_encounter_information.0003_auto_20160225_2130... OK
  Applying medical_encounter_information.0004_auto_20160225_2211... OK
  Applying medical_encounter_information.0005_auto_20160225_2211... OK
  Applying medical_encounter_information.0006_auto_20160225_2303... OK
  Applying medical_encounter_information.0007_auto_20160229_2204... OK
  Applying medical_encounter_information.0008_auto_20160229_2208... OK
  Applying medical_encounter_information.0009_auto_20160301_0130... OK
  Applying medical_encounter_information.0010_auto_20160301_0312... OK
  Applying medical_encounter_information.0011_auto_20160301_1525... OK
  Applying medical_encounter_information.0012_auto_20160301_1601... OK
  Applying medical_encounter_information.0013_auto_20160301_1606... OK
  Applying medical_encounter_information.0014_auto_20160301_1629... OK
  Applying medical_encounter_information.0015_auto_20160301_1633... OK
  Applying medical_encounter_information.0016_auto_20160301_1636... OK
  Applying sessions.0001_initial... OK
  Applying userprofiles.0004_auto_20160225_2211... OK
  Applying userprofiles.0005_auto_20160225_2211... OK
  Applying userprofiles.0006_auto_20160225_2303... OK
  Applying userprofiles.0007_auto_20160229_2204... OK
  Applying userprofiles.0008_auto_20160229_2208... OK
  Applying userprofiles.0009_auto_20160301_0130... OK
  Applying userprofiles.0010_auto_20160301_0312... OK
  Applying userprofiles.0011_auto_20160301_1525... OK
  Applying userprofiles.0012_auto_20160301_1601... OK
  Applying userprofiles.0013_auto_20160301_1606... OK
  Applying userprofiles.0014_auto_20160301_1629... OK
  Applying userprofiles.0015_auto_20160301_1633... OK
  Applying userprofiles.0016_auto_20160301_1636... OK
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

<强> 8。我在平台中部署的应用程序中创建了我的超级用户

(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ heroku run python manage.py createsuperuser
Running python manage.py createsuperuser on test-nrb.... up, run.7499
Username: bgarcial
Email address: bgarcial@eafit.edu.co
Password: 
Password (again): 
Superuser created successfully.
(nrb_dev) ➜  neurorehabilitation_projects git:(master) ✗ 

这就是全部。通过前面的过程,我们可以在heroky上部署一个Django应用程序