私はherokuに新しいですし、CSSなしで簡単なdjangoアプリを試しました。Django heroku static dir
しかし、私はちょうど私のアプリでCSSファイルを追加し、私はこれを行うとき:
git push heroku master
を静的ファイルの収集に失敗した:ここでは
[...]
-----> Collecting static files
Traceback (most recent call last):
File "manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 443, in execute_from_command_line
utility.execute()
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/management/__init__.py", line 382, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 196, in run_from_argv
self.execute(*args, **options.__dict__)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 232, in execute
output = self.handle(*args, **options)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/management/base.py", line 371, in handle
return self.handle_noargs(**options)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 163, in handle_noargs
collected = self.collect()
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 104, in collect
for path, storage in finder.list(self.ignore_patterns):
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/contrib/staticfiles/finders.py", line 105, in list
for path in utils.get_files(storage, ignore_patterns):
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/contrib/staticfiles/utils.py", line 25, in get_files
directories, files = storage.listdir(location)
File "/tmp/build_2unndirli15s7/.heroku/venv/lib/python2.7/site-packages/django/core/files/storage.py", line 235, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/home/kevin/web/django/appheroku/blogapp/static'
! Heroku push rejected, failed to compile Python/django app
To [email protected]:[...]
! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to '[email protected]:[...]'
は私のsettings.pyです:
[...]
STATIC_ROOT = '/home/kevin/web/django/appheroku/staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/kevin/web/django/appheroku/blogapp/static',
)
[...]
The urls.py:
[...]
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
Procfile:
web: python appheroku/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT appheroku/monblog/settings.py
それも、 '/ホーム/ケビン/ウェブ/ジャンゴ/ appheroku/blogapp /静的' ディレクトリは、それが検出されないと、私はその理由を把握することはできません、存在しているようです。 :(
^^私を助けてください
EDIT:
今私のsettings.pyは、次のようになります。
import os
PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__))
PROJECT_DIR = os.path.join(PROJECT_ROOT,'../blogapp')
[...]
STATIC_ROOT = os.path.join(PROJECT_ROOT,'staticfiles/')
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(PROJECT_DIR,'static/'),
)
[...]
そして今、静的なファイル収集ステップがうまく動作するようです:
-----> Collecting static files
74 static files copied.
別の問題がありました: 私のprocfileに 'appherok u/manage.py '、' bin/gunicorn_django '、' appheroku/monblog/settings.py 'が見つかりませんでした。 私はそれを固定し、今、私のprocfileは次のようになります。
web: python manage.py collectstatic --noinput; gunicorn_django --workers=4 --bind=0.0.0.0:$PORT monblog.settings
アプリはもうクラッシュしませんが、何のCSSはまだありません。ここ はログです:
'2012-05-31T17:35:16+00:00 heroku[router]: GET xxxx-xxxx-number.herokuapp.com/ dyno=web.1 queue=0 wait=0ms service=85ms status=200 bytes=1054
2012-05-31T17:35:17+00:00 heroku[router]: GET xxxx-xxxx-number.herokuapp.com/static/css/style.css dyno=web.1 queue=0 wait=0ms service=5ms status=404 bytes=2088
2012-05-31T17:35:17+00:00 heroku[router]: GET xxxx-xxxx-number.herokuapp.com/static/js/jquery-1.7.2.min.js dyno=web.1 queue=0 wait=0ms service=5ms status=404 bytes=2115'
EDIT3:
はい!それは動作します^^ 問題は私のurls.pyにあった。私が書いた:
[...]
if not settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
代わりの
[...]
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
エラーが私のメッセージではありませんでした...はい、私を助けるために本当に難しかったです。 (申し訳ありません)私はとても馬鹿だと感じています^^ '
私の編集で説明したように、このアプローチをいくつか変更して使用します。 (私の静的ディレクトリ( '静的/')は私のアプリケーションディレクトリ( 'blogapp /')の中にあるからです。それは私の問題を解決します(今でも私は別のものを持っています-_-) – heathen90
'blogapp /'はこの設定ファイルの親ディレクトリにありますか? 'blogapp 'は設定ファイルと同じディレクトリにある可能性が高くなります。つまり、' ../blogapp'の代わりに 'blogapp /'に参加するだけです。 –
appheroku /には、monblog /ディレクトリ、blogapp /ディレクトリ、staticfilesディレクトリが含まれています。 blogapp /ディレクトリには、models.pyファイル、views.pyファイル、admin.py、..(など)、静的/ディレクトリが含まれています。 monblog /ディレクトリにはsettings.py、urls.pyなどが含まれています – heathen90