Forums

Collectstatic failed

I got an error after introducing a static folder to my app. An "Error code: Unhandled Exception " shows up when I tried to load my website. I tried running collectstatic but only got the following error:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 338, 
in execute_from_command_line
    utility.execute()
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 330, 
in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 190, 
in fetch_command
    klass = load_command_class(app_name, subcommand)
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/management/__init__.py", line 41, i
n load_command_class
    return module.Command()
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/management/commands/
collectstatic.py", line 32, in __init__
    self.storage.path('')
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/utils/functional.py", line 226, in inner
    self._setup()
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 39
4, in _setup
    self._wrapped = get_storage_class(settings.STATICFILES_STORAGE)()
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/contrib/staticfiles/storage.py", line 39
, in __init__
    *args, **kwargs)
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/core/files/storage.py", line 186, in __i
nit__
    self.location = abspathu(self.base_location)
  File "/home/cqcum6er/my-first-blog/myvenv/local/lib/python2.7/site-packages/django/utils/_os.py", line 37, in abspathu
    if not isabs(path):
  File "/home/cqcum6er/my-first-blog/myvenv/lib/python2.7/posixpath.py", line 61, in isabs
    return s.startswith('/')
AttributeError: 'list' object has no attribute 'startswith'

The paths in settings.py were set to:

STATIC_URL = '/static/'

STATIC_ROOT = [ 
    os.path.join(BASE_DIR, 'static')
]

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static')
]

I also specify the URL and Directory under my Web tab, but nothing is working:(

Nvm, when I remove the square bracket [ ] from the file pathin the settings.py file, my website is loading properly now. But now when I run collectstatic, I got the following error:

django.core.exceptions.ImproperlyConfigured: Your STATICFILES_DIRS setting is not a tuple or list; perhaps you forgot a trailing comma?

Is there a conventional way of specifying static folder that I'm missing?

STATIC_ROOT needs to be a single directory, so you should specify it like this:

STATIC_ROOT = os.path.join(BASE_DIR, 'static')

STATICFILES_DIRS needs to be a list of directories, so you should specify it like this:

STATICFILES_DIRS = [ 
    os.path.join(BASE_DIR, 'static')
]

This help page has more details.

Ok that makes sense, thank you giles!

No problem! Let us know if you're still having issues.

Traceback (most recent call last): File "/home/AleksV/.local/bin/pa_autoconfigure_django.py", line 54, in <module> nuke=arguments.get('--nuke') File "/home/AleksV/.local/bin/pa_autoconfigure_django.py", line 39, in main project.run_collectstatic() File "/home/AleksV/.local/lib/python3.6/site-packages/pythonanywhere/django_project.py", line 126, in run_collectstatic '--noinput', File "/usr/lib/python3.6/subprocess.py", line 311, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command '['/home/AleksV/.virtualenvs/aleksv.pythonanywhere.com/bin/python', '/home/AleksV/aleksv.pythonanywhere.com/manage.py', 'collectstatic', '-- noinput']' returned non-zero exit status 1.

This is fucked up as hell!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Is your code in public repo so we could take a look at it?

Im getting similar error. Everything configured fine until the < running collectstatic ><Br> Here's my repo: GitHub Repo <br> <br> < Running collectstatic > <br> \ <br> ~<:>>>>>>>>> <br>Traceback (most recent call last): <br> File "/home/blssdlex/blssdlex.pythonanywhere.com/library_extensions/manage.py", line 22, in <module> <br> main() <br> File "/home/blssdlex/blssdlex.pythonanywhere.com/library_extensions/manage.py", line 18, in main <br> execute_from_command_line(sys.argv) <br> File "/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/lib/python3.10/site-<br>packages/django/core/management/init.py", line 442, in execute_from_command_line <br> utility.execute() <br>File "/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/lib/python3.10/site-packages/django/core/management/init.py", line 416, in execute <br> django.setup() <br>File "/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/lib/python3.10/site-packages/django/init.py", line 24, in setup <br> apps.populate(settings.INSTALLED_APPS) <br> File "/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/lib/python3.10/site-packages/django/apps/registry.py", line 91, in populate app_config = AppConfig.create(entry) File "/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/lib/python3.10/site-packages/django/apps/config.py", line 193, in create <br> import_module(entry) <br> File "/usr/local/lib/python3.10/importlib/init.py", line 126, in import_module <br> return _bootstrap._gcd_import(name[level:], package, level) <br> File "<frozen importlib._bootstrap>", line 1050, in _gcd_import <br> File "<frozen importlib._bootstrap>", line 1027, in _find_and_load <br> File "<frozen importlib._bootstrap>", line 1004, in _find_and_load_unlocked <br>ModuleNotFoundError: No module named 'crispy_forms' <br>Traceback (most recent call last): <br> File "/home/blssdlex/.local/bin/pa_autoconfigure_django.py", line 49, in <module> <br> main( <br> File "/home/blssdlex/.local/bin/pa_autoconfigure_django.py", line 39, in main <br> project.run_collectstatic() <br>File "/home/blssdlex/.local/lib/python3.10/site-packages/pythonanywhere/django_project.py", line 122, in run_collectstatic <br> subprocess.check_call([ <br> File "/usr/local/lib/python3.10/subprocess.py", line 369, in check_call <br> raise CalledProcessError(retcode, cmd) <br>subprocess.CalledProcessError: Command '['/home/blssdlex/.virtualenvs/blssdlex.pythonanywhere.com/bin/python', <br>'/home/blssdlex/blssdlex.pythonanywhere.com/library_extensions/manage.py', 'collectstatic', '--noinput']' returned non-zero exit status 1.

Try running the failing command manually and see what the error message is.