Forums

How collectstatic when settings is renamed and in another folder?

Hi! I'm trying to display admin static files at mywebsite.pythonanywhere.com/admin

These are the commands that are giving me errors:

python shell manage.py

(venv) $ python manage.py collectstatic
Unknown command: 'collectstatic'
Type 'manage.py help' for usage.

python shell django-admin.py

(venv) $ python django-admin.py collectstatic --settings=mysite.settings.prod
Unknown command: 'collectstatic'
Type 'django-admin.py help' for usage.

And this is my setup:

Tree

/mysite/mysite/settings
init__.py
base.py
dev.py
prod.py

wsgi file

import os
import sys

path = '/home/username/mysite'
if path not in sys.path:
    sys.path.append(path)
os.environ['DJANGO_SETTINGS_MODULE'] = 'mysite.settings.prod'
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

prod.py

from base import *
  DEBUG = False
 DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.mysql',
        'NAME': 'username$name',
        'USER': 'username',
        'PASSWORD': 'password',
        'HOST': 'username.mysql.pythonanywhere-services.com',
    }
}

Solved it refreshing not before typing the following:

(venv) export DJANGO_SETTINGS_MODULE="mysite.settings.prod"
(venv) python manage.py collectstatic
...
62 static files copied to '/home/username/mysite/mysite/static'.

However this still doesn't solves the problem. I can't see the admin CSS in mysite.pythonanywhere.com/admin because my static folder is in the directory folder.

Is it safe to move the files into static root?

Does this help? https://help.pythonanywhere.com/pages/DjangoStaticFiles

Hi, Harry.

Thanks! I read that before but it didn't help me.

What worked for me was to use my production settings before running manage.py collectstatic (as stated in my previous post) and then moved the files from the directory they landed to my custom static root folder. So from now on I'll use in production settings:

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
ROOT = os.path.dirname(BASE_DIR)
STATIC_ROOT = os.path.join(ROOT, 'static')

According to what I have read elsewhere is normal to then move your collected static files wherever you need them.

Thanks again!

sounds good!