该博客建议将以下内容放入我的Procfile
.
web: python myproject_django/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT myproject_django/settings.py
但是在 Heroku 上运行我的项目失败了。这是来自$ Heroku logs
:
app[web.1]: bash: bin/gunicorn_django: No such file or directory
所以gunicorn_django
缺少一个文件/目录。该文件/目录应该包含什么,我应该把它放在哪里?
树
.
├── Procfile
├── myproject_django
│ ├── admin
│ ├── core
│ ├── __init__.py
│ ├── manage.py
│ ├── project_static
│ ├── settings.py
│ ├── templates
│ ├── urls.py
└── requirements.txt
编辑
当我将我的项目更改Procfile
为web: python myproject_django/manage.py run_gunicorn -b 0.0.0.0:$PORT -w 3
我的项目时运行良好(也提供静态文件)。
然后当我推送到heroku,然后做heroku run python myproject_django/manage.py collectstatic
,heroku open
然后我的网站正在被提供,除了静态文件。
树(注意staticfiles
目录是空的)
.
├── Procfile
├── myproject_django
│ ├── admin
│ ├── core
│ │ ├── admin.py
│ │ ├── __init__.py
│ │ ├── models.py
│ │ ├── static
│ │ │ ├── css
│ │ │ │ ├── base.css
│ │ │ │ ├── layout.css
│ │ │ └── media
| | | ├── pek.ico
| │ │ ├── pek.png
| │ │ ├── pek_symbol.png
│ │ ├── tests.py
│ │ ├── views.py
│ ├── __init__.py
│ ├── manage.py
│ ├── settings.py
│ ├── staticfiles
│ ├── templates
│ │ └── core
│ │ ├── 404.html
│ │ ├── 500.html
│ │ ├── home.html
│ │ └── install.html
│ ├── urls.py
└── requirements.txt
在 settings.py
PROJECT_PATH = os.path.dirname(os.path.abspath(__file__))
MEDIA_ROOT = os.path.join(PROJECT_PATH, 'static/media')
STATIC_ROOT = os.path.join(PROJECT_PATH,'staticfiles')
STATICFILES_DIRS = (
os.path.join(PROJECT_PATH, 'core/static'),
)
Edit2(致马克西姆 R.)
从第一次编辑中的设置开始,我运行python myproject_django/manage.py collectstatic
,然后推送到 heroku。heroku open
仍然不提供静态文件。DEBUG=True
在返回 404 错误时单击图像: request url: http://myproject_django.herokuapp.com/static/media/pyk1.png
.
Edit3(致马克西姆 R.)
heroku 日志
2012-08-18T10:18:37+00:00 heroku[web.1]: State changed from up to starting
2012-08-18T10:18:37+00:00 heroku[slugc]: Slug compilation finished
2012-08-18T10:18:38+00:00 heroku[web.1]: Starting process with command `python myproject_django/manage.py run_gunicorn -b 0.0.0.0:47262 -w 3`
2012-08-18T10:18:39+00:00 app[web.1]: /app/myproject_django
2012-08-18T10:18:39+00:00 app[web.1]: STATIC_ROOT: /app/myproject_django/staticfiles
2012-08-18T10:18:39+00:00 app[web.1]: STATICFILES_DIRS: '/app/myproject_django/core/static'
2012-08-18T10:18:39+00:00 app[web.1]: STATIC_ROOT: /app/myproject_django/staticfiles
2012-08-18T10:18:39+00:00 app[web.1]: STATICFILES_DIRS: '/app/myproject_django/core/static'
2012-08-18T10:18:39+00:00 app[web.1]: /app/myproject_django
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [2] [INFO] Starting gunicorn 0.14.6
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [2] [INFO] Listening at: http://0.0.0.0:47262 (2)
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [2] [INFO] Using worker: sync
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [5] [INFO] Booting worker with pid: 5
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [6] [INFO] Booting worker with pid: 6
2012-08-18T10:18:39+00:00 app[web.1]: 2012-08-18 05:18:39 [7] [INFO] Booting worker with pid: 7
2012-08-18T10:18:39+00:00 app[web.1]: /app/myproject_django/app/myproject_django
2012-08-18T10:18:39+00:00 app[web.1]: /app/myproject_django
2012-08-18T10:18:39+00:00 app[web.1]: STATICFILES_DIRS: '/app/myproject_django/core/static'
2012-08-18T10:18:39+00:00 app[web.1]: STATIC_ROOT: /app/myproject_django/staticfilesSTATIC_ROOT: /app/myproject_django/staticfiles
2012-08-18T10:18:39+00:00 app[web.1]: STATICFILES_DIRS: '/app/myproject_django/core/static'
2012-08-18T10:18:39+00:00 app[web.1]:
2012-08-18T10:18:39+00:00 app[web.1]:
2012-08-18T10:18:39+00:00 app[web.1]: STATICFILES_DIRS: '/app/myproject_django/core/static'
2012-08-18T10:18:39+00:00 app[web.1]: STATIC_ROOT: /app/myproject_django/staticfiles
2012-08-18T10:18:40+00:00 heroku[web.1]: Stopping all processes with SIGTERM
2012-08-18T10:18:40+00:00 heroku[web.1]: State changed from starting to up
2012-08-18T10:18:41+00:00 app[web.1]: 2012-08-18 05:18:41 [7] [INFO] Worker exiting (pid: 7)
2012-08-18T10:18:41+00:00 app[web.1]: 2012-08-18 05:18:41 [2] [INFO] Handling signal: term
2012-08-18T10:18:41+00:00 app[web.1]: 2012-08-18 05:18:41 [6] [INFO] Worker exiting (pid: 6)
2012-08-18T10:18:41+00:00 app[web.1]: 2012-08-18 05:18:41 [5] [INFO] Worker exiting (pid: 5)
2012-08-18T10:18:41+00:00 app[web.1]: 2012-08-18 05:18:41 [2] [INFO] Shutting down: Master
2012-08-18T10:18:42+00:00 heroku[web.1]: Process exited with status 0
2012-08-18T10:18:43+00:00 heroku[router]: GET myproject.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=36ms status=200 bytes=5474
2012-08-18T10:18:43+00:00 heroku[router]: GET myproject.herokuapp.com/static/media/pek.png dyno=web.1 queue=0 wait=0ms service=16ms status=404 bytes=2613