3

I am trying to deploy my Django project on Digital Ocean. I created my droplet and spaces on Digital Ocean and created a static folder to store my static files. I pulled my code from my github-repo. then I installed all requirements and tried to collect static files with command

python3 manage.py collectstatic

but it shows

Unknown command: 'collectstatic'
Type 'manage.py help' for usage.

what should I do here?

I checked my manage.py helper but it has no command as collectstatic

    check,
    compilemessages,
    createcachetable,
    dbshell,
    diffsettings,
    dumpdata,
    flush,
    inspectdb,
    loaddata,
    makemessages,
    makemigrations,
    migrate,
    runserver,
    sendtestemail,
    shell,
    showmigrations,
    sqlflush,
    sqlmigrate,
    sqlsequencereset,
    squashmigrations,
    startapp,
    startproject,
    test,
    testserver,

these are the commands in manage.py helper.

And my settings.py is the following

import os
from pathlib import Path
from decouple import config

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = Path(__file__).resolve().parent.parent


DEBUG = config('DEBUG', default=False, cast=bool)

SECRET_KEY = config("SECRET_KEY")

ALLOWED_HOSTS = ["134.209.153.105",]

ROOT_URLCONF = f'{config("PROJECT_NAME")}.urls'

# Application definition

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.contrib.sites',

    'crispy_forms',

    'accounts',
    'adminn',
    'student',
    'union',
    'chat',
    'channels',

    'allauth',
    'allauth.account',
    'allauth.socialaccount',
    'allauth.socialaccount.providers.google',
]
    

AWS_ACCESS_KEY_ID = config('AWS_ACCESS_KEY_ID')
AWS_SECRET_ACCESS_KEY = config('AWS_SECRET_ACCESS_KEY')
AWS_STORAGE_BUCKET_NAME = config('AWS_STORAGE_BUCKET_NAME')
AWS_S3_ENDPOINT_URL = config('AWS_S3_ENDPOINT_URL')
AWS_S3_OBJECT_PARAMETERS = {
    'CacheControl': 'max-age=86400',
}
AWS_LOCATION = config('AWS_LOCATION')

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

STATIC_ROOT = os.path.join(BASE_DIR, 'static/')
STATIC_URL = 'https://%s/%s/' % (AWS_S3_ENDPOINT_URL, AWS_LOCATION)
TEMP = os.path.join(BASE_DIR, 'temp')
STATICFILES_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
DEFAULT_FILE_STORAGE = 'storages.backends.s3boto3.S3Boto3Storage'
  
BASE_URL = "http://134.209.153.105"

here, in static url AWS_STORAGE_BUCKET_NAME, AWS_S3_ENDPOINT_UR, AWS_LOCATION are following...

AWS_STORAGE_BUCKET_NAME=studentcricle
AWS_S3_ENDPOINT_URL=https://sfo3.digitaloceanspaces.com
AWS_LOCATION=studentcircle-static
Rasheed kotoor
  • 257
  • 2
  • 14

4 Answers4

5

Thank you for those who checked my question. My problem is solved as I run the following code.

export DJANGO_SETTINGS_MODULE=mysite.settings

I found it from Django documentation. But I still did not find out what was the real problem. It was something about my settings file. or multiple settings files

so, if anyone know the details, please describe it here. or in personal.

Rasheed kotoor
  • 257
  • 2
  • 14
0

I think you should uncomment STATIC_ROOT inside your settings.py file and try this:

STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
Darsh Modi
  • 289
  • 1
  • 9
0

First of all please check if there is a folder in base directory named 'static'; if yes, then make a little change in the following code, remove'/' after static:

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

Secondly, make sure you have registered all the apps in the installed apps menu.

If the problem still persists, then try to run the following command: python manage.py shell

It should let you know where the problem is, if it's in the settings.

Rohit_VE
  • 109
  • 5
  • still it is not working. I think the problem is with settings.py file. I think it is not properly defined in project or connecting to another file. – Rasheed kotoor Jul 06 '21 at 09:54
0

Try with replacing STATIC_ROOT in settings.py file with the following:

STATIC_ROOT = '/static/'

and whenever you run the python3 manage.py collectstatic command, make sure you are in the base directory where the manage.py file is located and there is a folder named static.

Rohit_VE
  • 109
  • 5