Forums

Admin css won't load when deploying Django project

So I had some trouble with static files when I tried deploying them... Thing is that I manage to server the main static files and everything is working except for the admin. I think maybe something is wrong with my configuration. Here is screenshot of my web: https://i.imgur.com/RtuStM2.png This is my settings.py:

import os

BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))

TEMPLATE_DIR = os.path.join(BASE_DIR, 'templates')
STATIC_DIR = os.path.join(BASE_DIR, 'static')
MEDIA_DIR = os.path.join(BASE_DIR, 'media')


SECRET_KEY = 'ie&_vj_d)t5itbpun3%*58tlw(3=ptn1^*5qj43kgm^&_z^!5('

DEBUG = False

ALLOWED_HOSTS = ['danielcirstea.pythonanywhere.com']



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

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',
    'django.middleware.locale.LocaleMiddleware'
]

ROOT_URLCONF = 'tango_with_django_project.urls'

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

LANGUAGE_CODE = 'ro'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


STATIC_ROOT = os.path.join(BASE_DIR, 'staticfiles')
STATICFILES_DIRS = [STATIC_DIR, ]
STATIC_URL = '/static/'


MEDIA_ROOT = MEDIA_DIR
MEDIA_URL = '/media/'



REGISTRATION_OPEN = True
ACCOUNT_ACTIVATION_DAYS = 7
REGISTRATION_AUTO_LOGIN = True
LOGIN_REDIRECT_URL = '/rango/'
LOGIN_URL = '/accounts/login/'

[edit by admin: formatting]

First things first -- the SECRET_KEY in your settings file is something you need to keep secret, and these forums are publicly-visible, so you should change it now for safety.

Regarding the admin CSS, the first line in your static files setup looks wrong -- I think the "URL" on that line should be /static/admin. If you change that and then reload the website from the "Web" page, the admin CSS should start working.

Negative. Same result.

Could you double-check that you actually made the change on the "Web" tab? I just looked at your website's configuration, and it doesn't look like it's changed.

It's done..still not good.

It's done..still not good.

I think you also have a space in the "Directory" field for the same line that should not be there, in between "django/" and "contrib".

Ok, this solved my admin. THhank you very much! But what about my about page ? image still not loaded.

Ok, this solved my admin. THhank you very much! But what about my about page ? image still not loaded.

You mean at http://danielcirstea.pythonanywhere.com/? I can see an image if I go there.

To me doesn't show the image on the about page (/rango/about). And if I refresh it then it crashed and gives error 500.

That pic points to /media/cat. You don't have a /media static files mapping for your webapp.

Yes. Thank you. Everything is working properly!

Excellent, glad we could work it out!