Sono nuovo di heroku e ho provato una semplice applicazione django senza css.Django heroku static dir
Ma ho solo aggiunto un file CSS nella mia app e quando faccio questo:
git push heroku master
La collezione file statico fallisce:
[...]
-----> 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]:[...]'
Ecco il mio settings.py:
[...]
STATIC_ROOT = '/home/kevin/web/django/appheroku/staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
'/home/kevin/web/django/appheroku/blogapp/static',
)
[...]
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
Sembra anche il '/ home/Kevin/web/django// appheroku blogapp/static' esiste directory, non è rilevato e non riesco a capire perché. :(
Please help me ^^
EDIT:
Ora il mio settings.py assomiglia a questo:
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/'),
)
[...]
Ed ora il passo collezione file statici sembra funzionare bene:
C'è stato un altro problema: nel mio procfile, 'appherok u/manage.py ',' bin/gunicorn_django 'e' appheroku/monblog/settings.py 'non sono stati trovati. ho riparato e ora il mio procfile assomiglia a questo:
web: python manage.py collectstatic --noinput; gunicorn_django --workers=4 --bind=0.0.0.0:$PORT monblog.settings
L'applicazione non va in crash più, ma non c'è ancora css. Ecco il log:
'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:
Sì! funziona ^^ Il problema era nella mia urls.py. Ho scritto:
[...]
if not settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
invece di
[...]
if settings.DEBUG:
urlpatterns += staticfiles_urlpatterns()
L'errore non era nel mio messaggio .. Sì, è stato davvero difficile per aiutarmi. (Mi dispiace) Mi sento così stupido ^^ '
Ora utilizzo questo approccio con alcune modifiche come spiegato nella mia modifica. (perché la mia dir statica ('static /') si trova nella mia app dir ('blogapp /')). Risolve il mio problema (anche ora sono con un altro -_-) – heathen90
'blogapp /' nella directory padre di questo file di impostazioni? Sembra più probabile che 'blogapp,' sia nella stessa directory del file delle impostazioni, il che significa che dovresti semplicemente unirti a 'blogapp /' invece di '../ blogapp'. –
appheroku/contiene la directory monblog /, la directory blogapp/e la directory staticfiles. La directory blogapp/contiene il file models.py, il file views.py, admin.py, .. (etc) e static/dir. La directory monblog/contiene il settings.py, l'urls.py, ecc ... – heathen90