0

I was going to deploy my app on heroku. I have set all of the paths such as STATIC_ROOT, STATIC_URL and STATICFILES_DIRS correctly. I am still getting the error.

Anyone knows whats wrong?

Traceback error

remote:        Traceback (most recent call last):
remote:          File "/tmp/build_64cf714d/manage.py", line 22, in <module>
remote:            main()
remote:          File "/tmp/build_64cf714d/manage.py", line 18, in main
remote:            execute_from_command_line(sys.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
remote:            utility.execute()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/__init__.py", line 413, in execute
remote:            self.fetch_command(subcommand).run_from_argv(self.argv)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 354, in run_from_argv
remote:            self.execute(*args, **cmd_options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/management/base.py", line 398, in execute
remote:            output = self.handle(*args, **options)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 187, in handle
remote:            collected = self.collect()
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/management/commands/collectstatic.py", line 128, in collect
remote:            for original_path, processed_path, processed in processor:
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/whitenoise/storage.py", line 148, in post_process_with_compression
remote:            for name, hashed_name, processed in files:
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/whitenoise/storage.py", line 88, in post_process
remote:            for name, hashed_name, processed in files:
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 399, in post_process
remote:            yield from super().post_process(*args, **kwargs)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 231, in post_process
remote:            for name, hashed_name, processed, _ in self._post_process(paths, adjustable_paths, hashed_files):
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 288, in _post_process
remote:            content = pattern.sub(converter, content)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 187, in converter
remote:            hashed_url = self._url(
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 126, in _url
remote:            hashed_name = hashed_name_func(*args)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 338, in _stored_name
remote:            cache_name = self.clean_name(self.hashed_name(name))
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/whitenoise/storage.py", line 166, in hashed_name
remote:            name = super(CompressedManifestStaticFilesStorage, self).hashed_name(
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 87, in hashed_name
remote:            if not self.exists(filename):
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 318, in exists
remote:            return os.path.exists(self.path(name))
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/contrib/staticfiles/storage.py", line 41, in path
remote:            return super().path(name)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/core/files/storage.py", line 331, in path
remote:            return safe_join(self.location, name)
remote:          File "/app/.heroku/python/lib/python3.9/site-packages/django/utils/_os.py", line 29, in safe_join
remote:            raise SuspiciousFileOperation(
remote:        django.core.exceptions.SuspiciousFileOperation: The joined path (/tmp/build_64cf714d/webfonts/fa-brands-400.eot) is located outside of the base path component (/tmp/build_64cf714d/staticfiles)
remote:
remote:  !     Error while running '$ python manage.py collectstatic --noinput'.
remote:        See traceback above for details.
remote:
remote:        You may need to update application code to resolve this error.
remote:        Or, you can disable collectstatic for this application:
remote:
remote:           $ heroku config:set DISABLE_COLLECTSTATIC=1
remote:
remote:        https://devcenter.heroku.com/articles/django-assets
remote:  !     Push rejected, failed to compile Python app.
remote:
remote:  !     Push failed
remote: Verifying deploy...
remote:
remote: !       Push rejected to iffi-store-app.
remote:
To https://git.heroku.com/iffi-store-app.git
 ! [remote rejected] master -> master (pre-receive hook declined)
error: failed to push some refs to 'https://git.heroku.com/iffi-store-app.git'

My settings.py

"""
Django settings for customise project.

Generated by 'django-admin startproject' using Django 3.2.

For more information on this file, see
https://docs.djangoproject.com/en/3.2/topics/settings/

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.2/ref/settings/
"""
import os
import django_heroku
from pathlib import Path

# Build paths inside the project like this: BASE_DIR / 'subdir'.
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.2/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'django-insecure-)chu4r&scuyncwba^on1go*9!1=k+*ip4fgs@z2n8d6$%@xt+3'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

INSTALLED_APPS = [
    'index',
    'cart',
    'crispy_forms',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
]

CRISPY_TEMPLATE_PACK = 'uni_form'

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'customise.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [
            os.path.join(BASE_DIR, "templates")
        ],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
                'django.template.context_processors.media',
            ],
        },
    },
]

WSGI_APPLICATION = 'customise.wsgi.application'


# Database
# https://docs.djangoproject.com/en/3.2/ref/settings/#databases

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': os.path.join(BASE_DIR, "db.sqlite3"),
        
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.2/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/3.2/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.2/howto/static-files/

STATIC_URL = '/static/'

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

# Default primary key field type
# https://docs.djangoproject.com/en/3.2/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'

MEDIA_ROOT = os.path.join(BASE_DIR, 'media')
MEDIA_URL = '/media/'

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

django_heroku.settings(locals())

Any help will surely be appreciated.

Neha AK
  • 67
  • 1
  • 10
  • have you run python manage.py collectstatic on local sevre – sarangkkl Nov 23 '21 at 06:51
  • Does this answer your question? [Collectstatic error while deploying Django app to Heroku](https://stackoverflow.com/questions/36665889/collectstatic-error-while-deploying-django-app-to-heroku) – Sumithran Nov 23 '21 at 08:29
  • heroku has a nice blog on how to server static files for django [here](https://devcenter.heroku.com/articles/django-assets) – mr blu Nov 23 '21 at 17:53
  • @sarangkkl no, I did not try that. – Neha AK Nov 23 '21 at 18:34
  • @Sumithran let me try all those solutions and I will update here. – Neha AK Nov 23 '21 at 18:38
  • @mrblu I have already the same Static paths as defined in the blog. – Neha AK Nov 23 '21 at 18:39
  • hmm..what is your DEBUG set to when deploying to heroku, have you separated your production and dev settings? – mr blu Nov 24 '21 at 09:18
  • `DEBUG` is set to `True` and no, I have not separated my production and dev settings. Do I really need to do that @mrblu? – Neha AK Nov 24 '21 at 12:53
  • Sorry for the late reply. You want to separate your production and development settings to effectively manage your deployment environments. [This article](https://www.hackadda.com/post/2020/2/21/separate-your-development-and-production-settings-for-a-django-project/) can help with that. – mr blu Nov 25 '21 at 09:05
  • 1
    You specify the environment by exporting the [DJANGO_SETTINGS_MODULE](https://docs.djangoproject.com/en/3.2/topics/settings/#envvar-DJANGO_SETTINGS_MODULE). – mr blu Nov 25 '21 at 09:05
  • 1
    So in heroku, at the [environment vars dashboard](https://devcenter.heroku.com/articles/config-vars), remember to set it to production. Also, in your production settings you want DEBUG set to false to tell django you will be serving static files yourself. Moreover, you need to add heroku to your ALLOWED_HOSTS setting. – mr blu Nov 25 '21 at 09:06
  • 1
    So, if heroku is in you allowed hosts, you have specified your production settings and your production settings look like this `DEBUG = False STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles') STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage' ` as per the blog, then you should be good to go – mr blu Nov 25 '21 at 09:09
  • @mrblu thank you for all the info, I will try it and let you know if it worked. – Neha AK Nov 25 '21 at 20:00
  • awesome, happy coding – mr blu Nov 28 '21 at 10:56

0 Answers0