Reputation: 501
i'm trying to run collect my static files on heroku so i ran the command:
heroku run python manage.py collectstatic --noinput
my settings file is:
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = 'staticfiles'
STATIC_URL = '/static/'
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'),
)
# define the directory which all upload files will be saved
PROJECT_ROOT = os.path.abspath(os.path.dirname(os.path.dirname(__file__)))
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'MyApp/media/')
MEDIA_URL = '/MyApp/media/'
and i got the following error message:
OSError: [Errno 2] No such file or directory: '/app/MyApp/static'
what does this mean?
why should i have a "static" file in "/app/MyApp"? isn't it supposed to be the
STATIC_ROOT?
full traceback:
Running `python manage.py collectstatic --noinput` attached to terminal... up, r
un.9966
Traceback (most recent call last):
File "manage.py", line 11, in <module>
execute_from_command_line(sys.argv)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/_
_init__.py", line 385, in execute_from_command_line
utility.execute()
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/_
_init__.py", line 377, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py",
line 288, in run_from_argv
self.execute(*args, **options.__dict__)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py", line 338, in execute
output = self.handle(*args, **options)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/management/base.py", line 533, in handle
return self.handle_noargs(**options)
File "/app/.heroku/python/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 168, in handle_noargs
collected = self.collect()
File "/app/.heroku/python/lib/python2.7/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/python2.7/sitepackages/django/contrib/staticfiles/finders.py", line 111, in list
for path in utils.get_files(storage, ignore_patterns):
File "/app/.heroku/python/lib/python2.7/sitepackages/django/contrib/staticfiles/utils.py", line 27, in get_files
directories, files = storage.listdir(location)
File "/app/.heroku/python/lib/python2.7/sitepackages/django/core/files/storage.py", line 270, in listdir
for entry in os.listdir(path):
OSError: [Errno 2] No such file or directory: '/app/CTFdj/static'
edited: OSError: [Errno 2] No such file or directory: '/app/CTFdj/static' =>>
OSError: [Errno 2] No such file or directory: '/app/MyApp/static'
Upvotes: 0
Views: 1020
Reputation: 880
I suspect your getting that error because your BASE_DIR
is not setup correctly for your project structure. Try running python manage.py collectstatic --noinput
locally to see if you get the same error. You can also print(BASE_DIR)
in settings.py
to check if it's pointing to the correct location, and that the static
folder is actually in that directory. For my projects, I have the settings file several levels deep, but the static
directory is at the root of the project, so my settings look like this:
BASE_DIR = os.path.dirname(os.path.dirname(os.path.dirname(__file__))) // base_dir/subdir/settings/settings.py
STATICFILES_DIRS = (
os.path.join(BASE_DIR, 'static'), // base_dir/static
)
Also, for my Heroku apps, I join BASE_DIR
and staticfiles
together for STATIC_ROOT
like this:
STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
On another note, I should warn you that you cannot upload media files directly to your Heroku app like you currently have setup with MEDIA_ROOT
. Heroku uses an ephemeral filesystem that discards files you write to it after the dyno is stopped or restarted. You'll need to use a 3rd party service like Amazon S3 to upload user submitted media files. The django-storages app can help with the integration.
Upvotes: 1
Reputation: 11824
I might not be able to answer why it is looking at /app/CTFdj/static
, but one possible reason is because your STATIC_ROOT
might have been configured wrongly. It should be the absolute path where the collected static will be copied to. Have a look at how I normally organize my STATIC_ROOT
. Hope this helps.
Upvotes: 0