2012-05-30 5 views
16

나는 heroku에 익숙하지 않고 css없이 간단한 django app를 시도했다.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 :

01 2,362,

Procfile :

그것은 디렉토리 존재조차 '/ appheroku/blogapp/정적/홈/케빈/웹/장고'가 감지되지 보인다
web: python appheroku/manage.py collectstatic --noinput; bin/gunicorn_django --workers=4 --bind=0.0.0.0:$PORT appheroku/monblog/settings.py 

나는 이유를 알아낼 수 없습니다.

지금 내 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() 

가 오류가 내 메시지에 .. 그래, 나를 도와 정말 어려웠다되지 않았습니다. (미안) 너무 어리 석다. ^^ '

답변

12

에 대한 절대 경로가 Heroku 서버에서 발견되지 않습니다.

해결하려면 다음 방법을 고려하십시오. 당신의 settings.py에서

은 : 사람들을위한

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) 
STATIC_ROOT= os.path.join(PROJECT_DIR,'staticfiles/') 
STATICFILES_DIRS = (
    os.path.join(PROJECT_ROOT,'static/'), 
) 
+0

이제이 편집 방법에서 설명한대로 일부 수정 사항을 사용하여이 접근법을 사용합니다. 내 정적 디렉토리 ('static /')가 내 app 디렉토리 ('blogapp /') 안에 있기 때문에. 내 문제를 해결한다. (심지어 지금은 다른 것을 가지고있다.) – heathen90

+0

'blogapp /'는이 설정 파일의 상위 디렉토리에 있는가? 'blogapp '는 설정 파일과 같은 디렉토리에있을 가능성이 높습니다. 즉,'../ blogapp' 대신'blogapp /'에 합류해야합니다. –

+0

appheroku /는 monblog/디렉토리의 blogapp/디렉토리와 staticfiles 디렉토리가 포함되어 있습니다. blogapp/디렉토리에는 models.py 파일, views.py 파일, admin.py, .. (etc) 및 정적/디렉토리가 들어 있습니다. monblog/디렉토리에는 settings.py, urls.py 등이 있습니다. – heathen90

3

당신은 곧 갈거야. 무슨 일이 일어나고 있는지 Heroku가 귀하의 컴퓨터에 로컬로 존재하지만 Heroku 서버에는 존재하지 않는 STATICFILES_DIRS 설정 (/ home/kevin/web/django/appheroku/blogapp/static)을 사용하려고합니다.당신은 그래서

간단한 해결책은 staticfiles_dir 변수에서 그 라인을 제거하는 것입니다 :

STATICFILES_DIRS =() 

그런 다음 기본 STATICFILES_FINDERS은에서 시작된다 당신은뿐만 아니라 모두 로컬 응용 프로그램을 실행하기 위해 갈 수 있어야한다 헤로 쿠에 배치.

+0

감사합니다. 지금은 이해합니다. 해결책은 "No such file or dir"오류를 없애고 다음과 같은 오류가 있습니다 : "Traceback (최근 호출 마지막) : OSError : [Errno 30] 읽기 전용 파일 시스템 : '/ home/kevin' – heathen90

+0

Kay Zhu 님의 추천으로 새로운 오류를 수정해야합니다. CSS가 표시되지 않는 경우 css 페이지로 바로 가려고 할 때 heroku 로그의 오류는 무엇입니까? "heroku logs --tail "명령 행에서 전화가 끊기는 부분을보다 잘 처리 할 수 ​​있습니다. – eliotk

+0

GET xxx-xxx-number.herokuapp.com/static/css/style.css dyno = web.1 queue = 0 wait = 0ms service = 6ms status = 404 bytes = 2088 – heathen90

1

나처럼 들어오는 누가 :

@eliotk이 의미처럼이

PROJECT_ROOT = os.path.abspath(os.path.dirname(__file__)) 
STATIC_ROOT= os.path.join(PROJECT_DIR,'staticfiles/') 
STATICFILES_DIRS =() 

이것은 당신이 FileNotFoundError: [Errno 2] No such file or directory:을 피하고자하는 설정입니다 오류 또는 OSError: [Errno 30] Read-only file system: 오류.