0
0
0ralo2021-02-16 19:09:14
Django
0ralo, 2021-02-16 19:09:14

Django + heroku losing static, how to fix?

In short, the second day I'm trying to deploy dzhanga to heroku - I constantly catch errors. Everything that could be fixed - fixed.
The project has unfolded, BUT, when I enter the admin panel, I see this
602bebd14c42f600732134.png
. In the console, this is:

log
2021-02-16T15:58:41.156157+00:00 app[web.1]: Not Found: /static/admin/css/nav_sidebar.css
2021-02-16T15:58:41.156820+00:00 app[web.1]: 10.29.170.202 - - [16/Feb/2021:15:58:41 +0000] "GET /static/admin/css/nav_sidebar.css HTTP/1.1" 404 2052 "https://testdeploy0.herokuapp.com/admin/login/?next=/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
2021-02-16T15:58:41.158826+00:00 heroku[router]: at=info method=GET path="/static/admin/css/nav_sidebar.css" host=testdeploy0.herokuapp.com request_id=39e04251-6d03-4a8c-b353-4383d74574bf fwd="81.177.127.240" dyno=web.1 connect=1ms service=10ms status=404 bytes=2292 protocol=https
2021-02-16T15:58:41.164782+00:00 app[web.1]: Not Found: /static/admin/css/base.css
2021-02-16T15:58:41.165533+00:00 app[web.1]: 10.95.230.181 - - [16/Feb/2021:15:58:41 +0000] "GET /static/admin/css/base.css HTTP/1.1" 404 2031 "https://testdeploy0.herokuapp.com/admin/login/?next=/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
2021-02-16T15:58:41.166568+00:00 heroku[router]: at=info method=GET path="/static/admin/css/base.css" host=testdeploy0.herokuapp.com request_id=77385739-4e71-423e-9993-b8795ce6280a fwd="81.177.127.240" dyno=web.1 connect=0ms service=16ms status=404 bytes=2271 protocol=https
2021-02-16T15:58:41.312401+00:00 app[web.1]: Not Found: /static/admin/css/login.css
2021-02-16T15:58:41.312844+00:00 app[web.1]: 10.29.170.202 - - [16/Feb/2021:15:58:41 +0000] "GET /static/admin/css/login.css HTTP/1.1" 404 2034 "https://testdeploy0.herokuapp.com/admin/login/?next=/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
2021-02-16T15:58:41.315123+00:00 heroku[router]: at=info method=GET path="/static/admin/css/login.css" host=testdeploy0.herokuapp.com request_id=0327bec3-da00-4119-ab62-982e78aaaa24 fwd="81.177.127.240" dyno=web.1 connect=1ms service=10ms status=404 bytes=2274 protocol=https
2021-02-16T15:58:41.317569+00:00 app[web.1]: Not Found: /static/admin/css/responsive.css
2021-02-16T15:58:41.318249+00:00 app[web.1]: 10.95.230.181 - - [16/Feb/2021:15:58:41 +0000] "GET /static/admin/css/responsive.css HTTP/1.1" 404 2049 "https://testdeploy0.herokuapp.com/admin/login/?next=/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"
2021-02-16T15:58:41.319731+00:00 heroku[router]: at=info method=GET path="/static/admin/css/responsive.css" host=testdeploy0.herokuapp.com request_id=63561805-6707-4c66-90c1-72f3b3a2d6f8 fwd="81.177.127.240" dyno=web.1 connect=0ms service=11ms status=404 bytes=2289 protocol=https
2021-02-16T15:58:41.438099+00:00 app[web.1]: Not Found: /static/admin/js/nav_sidebar.js
2021-02-16T15:58:41.438749+00:00 app[web.1]: 10.33.187.161 - - [16/Feb/2021:15:58:41 +0000] "GET /static/admin/js/nav_sidebar.js HTTP/1.1" 404 2046 "https://testdeploy0.herokuapp.com/admin/login/?next=/admin/" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.150 Safari/537.36"



It turns out that the statics are not located, however, the statics folder has been created on the server

602bece257dab764345273.png

Please help me set up statics ((
If anything:
settings.py
"""
Django settings for test_deploy project.

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

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

For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.1/ref/settings/
"""

from pathlib import Path

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


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

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '!fqclhm([email protected]&5=919soqi(=x^mo4qmwb^_dgikbtc%1h0&iaz'

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

ALLOWED_HOSTS = ["*"]


# Application definition

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

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 = 'test_deploy.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        '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',
            ],
        },
    },
]

WSGI_APPLICATION = 'test_deploy.wsgi.application'


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

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.sqlite3',
        'NAME': BASE_DIR / 'db.sqlite3',
    }
}


# Password validation
# https://docs.djangoproject.com/en/3.1/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.1/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.1/howto/static-files/

STATIC_URL = '/static/'
STATIC_ROOT = BASE_DIR / 'static'
#STATICFILES_DIRS = (
#        BASE_DIR / 'static',
#)


or the whole project:

github
https://github.com/0ralo/testdeploy

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey Gornostaev, 2021-02-16
@0ralo

https://devcenter.heroku.com/articles/django-assets

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question